Filter löschen
Filter löschen

element values of matrix.

2 Ansichten (letzte 30 Tage)
Akmyrat
Akmyrat am 26 Mai 2014
Kommentiert: Star Strider am 26 Mai 2014
Lets say i have matrix A=[1 2 2;1 2 2;2 1 2;2 2 2]. if i do this code:
[m,n]=size(A)
for j = 1
for i = 1:m
if(ACM(i,j)==1)
C=(i,j)
end
end
end
%this program gives me the position of elements whose value is equal to 1. And there are 2 rows from 1st columns values are is 2. so i want that the rows whose elemnt is 1 need to be equal to "20", and the rest rows whose element is 2 , need to be "3". And multiply them according to sequence. in this case C will be resulted C=(1,1) C=(2,1), these are together represents "20", and with rest 3rd and 4th rows are 2s. which represent "3" . So result i want this 20*3*3=180. i hope i could explain :)

Akzeptierte Antwort

Star Strider
Star Strider am 26 Mai 2014
I am not certain I understand what you want, but this seems to come close:
A=[1 2 2;1 2 2;2 1 2;2 2 2];
C = A;
C(C==1) = 20; % Use ‘logical indexing’
C(C==2) = 3;
C = prod(C,2) % Take product along rows, across columns
produces:
C =
180.0000
180.0000
180.0000
27.0000
  2 Kommentare
Akmyrat
Akmyrat am 26 Mai 2014
not exactly what i want...but anyway thanks a lot .
Star Strider
Star Strider am 26 Mai 2014
My pleasure!
If it’s not exactly what you want,
  • what does it do that you don’t want it to do, or
  • what doesn’t it do that you want it to do?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices 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