Undefined operator / for input arguements of type cell.

1 view (last 30 days)
I realize this question may have been asked a billion times, but I can't for the life of me see why its popping up with my code. I'm calculating the maximum value in a data set 'bridge1Load' through this loop:
maxLoad1 = 0;
for n = 1:length(bridge1Load)
for k = 1
if bridge1Load(n, k) > maxLoad1
maxLoad1 = bridge1Load(n, k);
end
end
end
and my bridge weight is a user input from:
bridge1WeightInput = inputdlg('Please enter the weight of bridge #1','Bridge #1 Weight');
I'm trying to calculate the strength to weight ratio via:
s2wRatio1 = maxLoad1 / bridge1Weight;
but I keep getting the error stated above.
  2 Comments
Anas Abou Allaban
Anas Abou Allaban on 11 Oct 2015
Note that I used str2num and it still didnt work:
bridge1Weight = str2num(bridge1WeightInput);
dpb
dpb on 11 Oct 2015
bridge1Load must be a cell array, not a double, then. A likely candidate to have caused that would be reading the data from a file via textscan.
The best solution relies somewhat on just what the form of the data are; how was it actually loaded/obtained and specifically, what does
whos bridge1Load
return?
Then we can look at "more better" ways to do the above as well...

Sign in to comment.

Accepted Answer

Anas Abou Allaban
Anas Abou Allaban on 11 Oct 2015
Please ignore this rather silly question, I had to use str2double.....
  1 Comment
dpb
dpb on 11 Oct 2015
OK, although I'dve thunk that'd given a message regarding cell strings, not just cell.
Anyway, as noted, "the Matlab way" for the above once you have the 2D array (matrix) is
maxload1=max(bridge1Load(:);
no loops needed. The {:} returns the array as a vector, hence the maximum will be found over all elements in the array, otherwise, max operates by column so one often sees such code as
maxload1=max(max(bridge1Load));
to do the same thing. (Try a small array of random values at the command line to see how it works).
You're not keeping track of the location at which the max occurs above; one would presume that also will be of some interest before you're done completely. For that, use the optional index returned by max and convert to the row/column position in the array via ind2sub
[maxload1,imx]=max(max(bridge1Load));
[rmax,cmax]=ind2sub(size(bridge1Load),imx);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!