How to use each value of a matrix in certain formula and also save its result
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Safi ullah
el 1 de Mzo. de 2017
Respondida: KSSV
el 1 de Mzo. de 2017
Hi,I have a matrix having size Y=54×20.I want to use each element (value) of “Y” into the formula Q=(2-squrt(valueofY))./ squrt(valueofY) and save its result.I've tried the following,
P=zeros(54,20);
for j=1:1080;
Q=(2-sqrt(j))./sqrt(j);
P(j,:)=Q;
end
0 comentarios
Respuesta aceptada
KSSV
el 1 de Mzo. de 2017
Y=rand(54,20);
%%vectorized
A = (2-(Y.^0.5))./(Y.^0.5) ;
%%using loop
[m,n] = size(Y) ;
B = zeros(m,n) ;
for i = 1:m
for j = 1:n
B(i,j) = (2-sqrt(Y(i,j)))/sqrt(Y(i,j));
end
end
You need not to use loop in matlab. Straight away you can use matrices.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!