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

What does
whos fdValue
show?
Guillaume
Guillaume 2015년 10월 13일
I think it's clear that fdValue is a cell array since it can't be bridgeDisp (otherwise the error would be on the rectangle1 line).
Why is fdValue a cell array? Can we see how fdValue is created?
Anas Abou Allaban
Anas Abou Allaban 2015년 10월 13일
편집: Anas Abou Allaban 2015년 10월 13일
Its supposed to be a variable of type double, its an input from a user
Name Size Bytes Class Attributes
fdValue 1x1 118 cell
I just added
fdValue = str2double(fdValue);
in my main function and that let it loop through...I'm guessing thats the solution. Unless you had another suggestion?
fdValue = inputdlg('text');
Thats how it was created, I just noticed that inputdlg does not conver to string and that why I added
str2double

댓글을 달려면 로그인하십시오.

 채택된 답변

per isakson
per isakson 2015년 10월 13일
편집: per isakson 2015년 10월 13일

0 개 추천

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

Since fdValue was made like this:
fdValue = inputdlg('text'):
So I added i converted it to double by adding on the next line
fdValue = str2double(fdValue);
and that fixed it
per isakson
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개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2015년 10월 13일

편집:

2015년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by