Hot to display a variable from a row ?
古いコメントを表示
EXAMPLE
mSTAT=[1 2 3 4 5 6];
m34=[1.6 3.3 45.4 5.6 1.2 3.2];
Er=0.05;
for i=1:lenght(mSTAS)
j=1:lenght(m34)
if (m34(j)-mSTAS(i)<=Er)
disp([m34= ' num2str(m34(j))]);
end
end
The problem is that a don't know how to display just one variable from the row.
回答 (2 件)
James Tursa
2014 年 10 月 20 日
Looks like a typo, missing ' in your code. Try this:
disp(['m34= ' num2str(m34(j))]);
Roger Stafford
2014 年 10 月 20 日
編集済み: Roger Stafford
2014 年 10 月 20 日
Writing
j=1:length(m34)
makes 'j' a vector with six elements, and therefore
m34(j)-mSTAS(i)<=Er
is a logical vector with six elements. Using it as the condition with 'if' will require that all six elements are true simultaneously for the 'if' to be satisfied. For that reason your display will never occur.
Probably you need to use nested for-loops to do what you apparently want:
for i=1:length(mSTAS)
for j = 1:length(m34)
if abs(m34(j)-mSTAS(i))<=Er
display ....
カテゴリ
ヘルプ センター および File Exchange で Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!