Performing operations using variables created by For Loop outputs

Using a previous For Loop, I have created 704 3x3 matrices defined as N1uik, N2uik, N3uik...N704uik. (All values contained are real numbers)
I now want to use elements of these matrices as part of another For Loop, to create various other matrices named x1,x2,x3...x704.
I have tried:
For n=13:692
x(1,1)=((N(n-11)uik(1,3))-(N(n+11)uik(1,3)))/2;
x(1,2)=((N(n-1)uik(1,3))-(N(n+1)uik(1,3)))/3;
x(1,3)=0
eval(sprintf('x%d=x',n));
end
Obviously recalling values from the previously defined variables in this "N(n+1)uik" way does not work. How can this be done?
Thanks

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 9 日
編集済み: Azzi Abdelmalek 2013 年 3 月 9 日

1 投票

This is incorrect expression
N(n-11)uik(1,3)
Why have you created all those variables, while you could use one array 704x3x3?

5 件のコメント

Craig
Craig 2013 年 3 月 9 日
Yes so for example when n=13, using this how would I recall the 1st row, 3rd column value of "N2uik"? (eg (n-11) when in format Nnuik)
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 9 日
編集済み: Azzi Abdelmalek 2013 年 3 月 9 日
If A is your 704x3x3 array
%N2uik is A(2,:,:)
out=A(2,1,3)
You don't need all those variables
Matt J
Matt J 2013 年 3 月 9 日
編集済み: Matt J 2013 年 3 月 9 日
It was a mistake to create individual variables named N1uik, N2uik, N3uik...N704uik.
You should have made a 3x3x704 array named Nuik with each slice Nuik(:,:,n) containing the thing you now call Nnuik. Go back and fix that.
It will be a further mistake to create individual variables named x1,x2,x3...x704. Store them instead as x(1), x(2),...x(704).
Craig
Craig 2013 年 3 月 9 日
編集済み: Craig 2013 年 3 月 9 日
Okay thank you both very much for your help,
I have gone back and gathered the 3x3 arrays into one 3x3x704. This not only works but makes things much neater also.
How can I store the outputs as x(1) instead of x1?
eval(sprintf('x(%d)=x',n));
Is incorrect.
Thanks again
Matt J
Matt J 2013 年 3 月 9 日
編集済み: Matt J 2013 年 3 月 9 日
x=zeros(length(13:692),3);
for n=13:692
i=n-12;
x(i,1)=( Nuik(1,3,n-11) - Nuik(1,3,n+11) )/2;
x(i,2)=( Nuik(1,3,n-1) - Nuik(1,3,n+1) )/3;;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by