MATLAB: How can I fix the error “Conversion to cell from double is not possible.” at line 61 ???

distancematrix

for o=1:length(lat);
for d=1:length(lat)
if o==d
else
url = ['https://maps.googleapis.com/maps/api/distancematrix/json?origins=',...
num2str(lat(o)),',',num2str(long(o)),'&destinations=',...
num2str(lat(d)),',',num2str(long(d)),...
'&key=AIzaSyBmMhgsiLCgxseGraNjmUwRd4jONszCPuo'];
str = urlread(url);n=n+1;
data2(n)= JSON.parse(str);
status=data2(n).rows{1,1}.elements{1,1}.status;
if strcmp(status,'ZERO_RESULTS');
MatriceDelleDurate(o,d)=100000000;
MatriceDelleDistanze(o,d)=100000000;
else
MatriceDelleDurate(o,d)=data2(n).rows{1,1}.elements{1,1}.duration.value;
MatriceDelleDistanze(o,d)=data2(n).rows{1,1}.elements{1,1}.distance.value;
end
end
end
end

Best Answer

It appears to me that you initialized MatriceDelleDurate as a cell array, but you are trying to store double into the entries. If you do want a cell array, then instead of assigning to MatriceDelleDurate(o,d) you should be assigning to MatriceDelleDurate{o,d}
Related Question