Problem with double use of a for loop?

2 Ansichten (letzte 30 Tage)
Ivan Mich
Ivan Mich am 13 Nov. 2022
Kommentiert: Stephen23 am 14 Nov. 2022
I have a problem aith a code. I have 2 matrices , A and B. Matrix A has 3x3 dimensions, while matrix B has 1x3 dimensions. I would like to minus (remove with "-"), the (1,1) number of B from each one number (each line) of the 1st column of A matrix.
After that, I I would like to minus (remove with "-"), the (1,2) number of B from each one number (each line) of the 2nd column of A matrix.
Last, I would like to minus (remove with "-"), the (1,3) number of B from each one number (each line) of the 3rd column of A matrix.
I tried these commands:
ndata=size(A,1)
[rows columns] = size(B);
for jj=1:size(A,1);
for zz=(columns);
MINUS(jj)=(A(:,jj))- B(1,zz);
end
end
but no use. Could you please help me?
  5 Kommentare
Steven Lord
Steven Lord am 14 Nov. 2022
One potential reason to use a for loop would be if the poster is using an older release of MATLAB, one that predates the introduction of implicit expansion. Another is if this is a homework assignment and the professor or teacher that assigned the work forbade the students from using implicit expansion.
Stephen23
Stephen23 am 14 Nov. 2022
"One potential reason to use a for loop would be if the poster is using an older release of MATLAB, one that predates the introduction of implicit expansion"

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Stephen23
Stephen23 am 13 Nov. 2022
A-B

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by