If statement for a cell??

조회 수: 2 (최근 30일)
Jay
Jay 2014년 10월 31일
편집: Orion 2014년 10월 31일
I am trying to see if a column in a cell has string matching to what I stipulate.
I have read info on cells and still can not understand how to get this to return an answer.
The cell has integers 1:4 for the first column, then strings for the next column, then numerical values for rows 3 and 4.
I.e.
Point_list=
{'Point',1,2,3,4;'Type','Fixed','Unfixed','Unfixed','Unfixed';'X',800.000,120.000,2400.000,7210.000;'Y',60.000,700.000,1630.000,6320.000}
What I am trying to achieve:
If the string states 'Fixed' then return value 7
else return value 15.
Code I am using:
v(1,1) = zeros
if Points_list {:,2} strcmp(:,'Fixed')
v(1,1) = 7
else
v(1,1) = 15
end
What is the easiest way to get what I would like?
Thanks.

채택된 답변

Orion
Orion 2014년 10월 31일
편집: Orion 2014년 10월 31일
one way to do this is :
% create the cell data
Point_list={'Point',1,2,3,4;'Type','Fixed','Unfixed','Unfixed','Unfixed';'X',800.000,120.000,2400.000,7210.000;'Y',60.000,700.000,1630.000,6320.000};
% initialize all value to 7
ValueFixedUnfixed = 7*ones(1,size(Point_list,2)-1);
% compare 2nd row from 2nd col until end with string Unfixed and change corresponding value to 15 in the variable ValueFixedUnfixed
ValueFixedUnfixed(strcmp(Point_list(2,2:end),'Unfixed')) = 15;
% display to confirm
disp(Point_list(2,2:end))
disp(ValueFixedUnfixed)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by