- You can get the dimensions/ size of a matrix using size.
- You can comapre the elements using inequalitties >, <. >=, <=.
- Also you can use logical indices striaght away with out loop.
- To add you have to use +.
How to use for loop compare all values in a 2x2 matrix?
2 次查看(过去 30 天)
显示 更早的评论
Hi.
I'm a beginner and I'm just starting to learn Matlab so I'm not very familiar with the code syntax right now. But I'm working on the following problem.
A = [1, 2; 4, 6]
How do you use for loop to compare all the values in A to see which ones are greater than 3 and have those added together to make D?
Thanks.
0 个评论
采纳的回答
KSSV
2020-10-29
It is your home work...so you have to do it yourself. Follow the below hints.
5 个评论
KSSV
2020-10-29
You can try what A(:) prints, in command window instead of asking a question. This will help ypu to understand yourself. Anything, you have a doubts just type in command window and see it. You can get yourself.
A(:) this will make a matrix into a single column vector.
idx gives logical indices whose values are >3.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!