Loop to a specific point in data set
3 次查看(过去 30 天)
显示 更早的评论
I have a function used to loop through a data set and I want it to stop once the data reaches a specific threshold (In this case, the failure displacement value 'fdValue'. However, I keep getting the error for the if statement:
Undefined function 'ge' for input arguments of type 'cell'.
I think 'cellfun' can be used in this case but I'm not sure how to use it. Any Suggestions? Below is the function
totalRect = 0;
for j = 2:length(bridgeDisp)
%Calculations
rectangle1 = (bridgeDisp(j, 1) - bridgeDisp(j-1, 1))*((bridgeLoad(j, 1) + bridgeLoad(j-1, 1))/2);
totalRect = totalRect + rectangle1;
%If statment error
if bridgeDisp(j, 1) >= fdValue
break;
end
end
4 个评论
采纳的回答
per isakson
2015-10-13
编辑:per isakson
2015-10-13
Why is fdValue a cell array in the first place?
I assume the cell array contains a numerical scalar. If so replace
bridgeDisp(j, 1) >= fdValue
by
bridgeDisp(j, 1) >= fdValue{1}
or maybe by
bridgeDisp(j, 1) >= str2double(fdValue{1})
if the cell arrays contains a string
2 个评论
per isakson
2015-10-13
编辑:per isakson
2015-10-13
Note that not all functions take a cell array of a string in place of a string, as does str2double. Excerpt of documentation
X = str2double(C) converts the strings in the cell array of strings C to double precision.
However, str2num does not!
>> str2double({'17'})
ans =
17
>> str2num({'17'})
Error using str2num (line 33)
Requires string or character array input.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!