Reading a string value stored in an element of a matrix and compare it to a string
古いコメントを表示
There are three strings such as :
A='sfdgkl';
B='yuiopt';
C='qwerty';
I permutate them and make a matrix of it.
Then put the elemnts of the matrix in variables aA, bB, and cC in a forloop, in the end, I need to compare the string left in aA, bB, cC with A,B,C and find out that for example if it is A which is stored in aA, or it is B or it is C, and the same about bB, and cC.
I try this:
To compare the value of aA with a string say 'A' as mentioned above
However I just get false or '0' values out of this comparison. I have tride strcmp, and isequel functions for matter.
An example could be
if isequal(aA, A)
disp('hello');
elseif isequal(bB, A)
disp('hello2');
elseif isequal(cC, A)
disp('hello3');
end
but
I only get a logical '0' out of this and the if-statement does not do what I'm looking for.
The only output is:
ans =
logical
0
however if I test:
if isequal('hello', 'hello')
disp('hello');
end
the output is a logical 1 or true:
ans =
logical
1
So I understand that the problem could be reading the value stored in the matrix element. But would there be any idea how to extract that value and be able to compare it with a string?
*If I write:
aA
I will get output the string which is stored in it, this might help to know the challenge better? So there is a string in aA and a string in A, but it looks like when I compare it does not compare the string inisde aA with A.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!