Can't Build Vector in While loop

2 Ansichten (letzte 30 Tage)
John Jacoby
John Jacoby am 18 Jul. 2017
Kommentiert: John Jacoby am 18 Jul. 2017
Hi all, I need to search through some data and extract a specific value and then put all these values together into a vector. Here's the code I'm working with:
chtype = channels{1,1}.hdr.channeltype;
n=1;
while chtype ~= 'Edge'
size = size(channels{n,1}.mrk, 1);
sizeVec(n) = size;
n = n+1;
chtype = channels{n,1}.hdr.channeltype;
end
I get the following error:
Matrix dimensions must agree.
Error in RFSize1 (line 11) while chtype ~= 'Edge'
To me it looks like I'm just adding onto vector sizeVec with value size. I'm not sure what dimension isn't in agreement. Thank you!

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 18 Jul. 2017
Bearbeitet: Geoff Hayes am 18 Jul. 2017
John - when comparing strings, use strcmpi or strcmp. The first would be used if you are making a case-insensitive comparison, the second if you care about case. Your code would then become
while ~strcmp(chtype,'Edge')
or
while ~strcmpi(chtype,'Edge')
Note that the error Matrix dimensions must agree. makes sense when comparing
chtype ~= 'Edge'
since chtype may have a different number of elements from the four character 'Edge'.
  1 Kommentar
John Jacoby
John Jacoby am 18 Jul. 2017
Thank you so much, I'm new and forgot that 'matrix' could refer to a string as well.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by