How to check value in matrix from 2 specific column
2 次查看(过去 30 天)
显示 更早的评论
I have a data of
linedata = [1 1 2 2
2 2 3 1.5
3 3 4 2.2
4 4 5 6.8
5 4 6 1
6 5 7 5.1
7 6 8 2.5
8 7 9 3.3
9 8 10 2.8
10 8 11 1.4
11 10 12 3.2
12 11 13 2.7
13 12 14 1.9
14 13 15 4.5];
I would like to ask how can i check for value 7 and 8 in column 2 and column 3. I am using find function to find the value but it cant seems to work. Can anyone help? Thanks in advance.
2 个评论
the cyclist
2020-12-21
It is unclear to me exactly what you want. Do you want to check the two columns separately? Or are you trying to check the condition in both columns?
For example, are you trying to check if column 2 is equal to 7, while column 3 is equal to 8?
Do you need the indices, or is logical output ok?
Can you tell us what exactly you expect the output to be for this input? (Better to express it in MATLAB syntax, not English words.)
回答(1 个)
Image Analyst
2020-12-21
Explain exactly what "check for" means. Until then, try
% See if row 7 and 8, both in column 2, match
if linedata(7, 2) == linedata(8, 2)
fprintf(['linedata(7, 2) equals linedata(8, 2)\n');
else
fprintf(['linedata(7, 2) does not equal linedata(8, 2)\n');
end
% See if row 7 and 8, both in column 2, match
if linedata(7, 3) == linedata(8, 3)
fprintf(['linedata(7, 3) equals linedata(8, 3)\n');
else
fprintf(['linedata(7, 3) does not equal linedata(8, 3)\n');
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!