How to use each value of a matrix in certain formula and also save its result
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
KSSV
2017 年 3 月 1 日
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 件のコメント
その他の回答 (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!