Undefined operator / for input arguements of type cell.

11 次查看(过去 30 天)
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 个评论
Anas Abou Allaban
Anas Abou Allaban 2015-10-11
Note that I used str2num and it still didnt work:
bridge1Weight = str2num(bridge1WeightInput);
dpb
dpb 2015-10-11
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...

请先登录,再进行评论。

采纳的回答

Anas Abou Allaban
Anas Abou Allaban 2015-10-11
Please ignore this rather silly question, I had to use str2double.....
  1 个评论
dpb
dpb 2015-10-11
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by