If statement for a cell??

2 visualizzazioni (ultimi 30 giorni)
Jay
Jay il 31 Ott 2014
Modificato: Orion il 31 Ott 2014
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.

Risposta accettata

Orion
Orion il 31 Ott 2014
Modificato: Orion il 31 Ott 2014
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)

Più risposte (0)

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by