If statement without loop
14 次查看(过去 30 天)
显示 更早的评论
Hi there are two questions I wish to ask:
First, I would like to use if else statement without the loop. Here is my attempt with the loop:
for k=1:15
for j=1:10
if A(j,k) > B(j,1), C(j,k)=0;
else
C(j,k)=A(j,k);
end
end
end
toc;
This took some computation time but I wish to cutdown the time. I attempt to use:
TR1_Ge70(TR>TR_Ge&)=0;
However, the matrix dimension is incorrect. Here is the example:
Matrix A Matrix B Matrix C
1 2 3 4 5 3 1 2 0 0 0
1 2 3 4 5 2 1 0 0 0 0
1 2 3 4 5 1 0 0 0 0 0
1 2 3 4 5 5 1 2 3 4 0
The second question will be bit massive and I fail to write one. I have a matrix A, let say 3 by 3. I also have matrix B, let say 3 by 3 as well. I wish to multiple the first column of matrix A with the entire matrix B, and the scond column and etc. For example:
Matrix A Matrix B Outcome using first column A: Outcome using second column B:
1 2 2 2 2 1 2 2 1 4 4 2
3 3 2 3 3 2 9 9 6 9 9 6
4 2 3 1 2 1 4 8 4 2 4 2
Based on this, I will get three set outcomes. However, it's seem like I cannot write the code and give me three different outcomes directly. The only way that I think is that I have to maintain only single column of Matrix A, and change it every time in order to get three different outcomes. Is it a quick way to do this? Thank you so much for the help!
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!