フィルターのクリア

How to combine this value ?

6 ビュー (過去 30 日間)
Matlab111
Matlab111 2015 年 2 月 3 日
コメント済み: Stalin Samuel 2015 年 2 月 4 日
Actually i want to store the value, for example
clc
clear all
close all
for k=1:2
allR11=rand(1,10);
d6=length(allR11);
j1=1;
for op=1:d6
allR1_1(j1) = allR11(op)*rand;
op=op+1;
j1=j1+1;
end
d=allR1_1
end
After running this code you will get the 'd' values for two time that is when an 'k=1 and k=2' in for loop.
And now i want to store the values of 'd' values like this
sol=[0.1823 0.0894 0.0315 0.1297 0.5409 0.2566 0.2421 0.3433 0.1777 0.0256
0.0082 0.6125 0.3215 0.0009 0.1636 0.1705 0.0813 0.0707 0.3140 0.1515];
in this 'sol', it has 20 columns, it's like, it's storing both the values of 'd' when 'k=1 and k=2'
so finally i want to get like that 'sol'

採用された回答

Stalin Samuel
Stalin Samuel 2015 年 2 月 4 日
sol=[allR11 allR1_1]
  2 件のコメント
Matlab111
Matlab111 2015 年 2 月 4 日
ya i can get but i want to get with in the loop itself ...
Stalin Samuel
Stalin Samuel 2015 年 2 月 4 日
clc
clear all
close all
sol=0
for k=1:2
allR11=rand(1,10);
d6=length(allR11);
sol = allR11
j1=1;
for op=1:d6
allR1_1(j1) = allR11(op)*rand;
op=op+1;
j1=j1+1;
end
sol (end+1:numel(allR11)+numel(allR1_1))= allR1_1
d=allR1_1
end

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

その他の回答 (3 件)

karthik
karthik 2015 年 2 月 3 日
編集済み: karthik 2015 年 2 月 3 日
Your question is not clear.. How do you want the solution to be?
sol=[0.1823 0.0894 0.0315 0.1297 0.5409 0.2566 0.2421 0.3433 0.1777 0.0256
0.0082 0.6125 0.3215 0.0009 0.1636 0.1705 0.0813 0.0707 0.3140 0.1515];
Is this the solution you get after running your code?
  1 件のコメント
Matlab111
Matlab111 2015 年 2 月 4 日
ya after running the code i want to get all the 20 values in one variable ...

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


Roger Stafford
Roger Stafford 2015 年 2 月 4 日
If you want all twenty values to be stored in 'sol', you need to move the line
j1=1;
to execute before entering the outer 'for' loop:
...
j1 = 1;
for k=1:2
...
That way you will get twenty successive values placed in the 'sol' array.
As your code is at present, j1 is reset to 1 so you write over the ten values in 'sol' with the second ten, and the first ten are therefore lost forever. All that remains is the display of them on your screen.
Note: The line "op=op+1" is totally useless. The inner for-loop
for op=1:d6
does that for you automatically, and in fact will overwrite any changes you make to 'op' within the loop. You should never modify the 'for' index within its loop.
  2 件のコメント
Matlab111
Matlab111 2015 年 2 月 4 日
so how i modifies this code to get that all the values in one variable..
Roger Stafford
Roger Stafford 2015 年 2 月 4 日
I already told you how to modify your code. Move the line "j1=1;" to a position before you enter the "for k=1:2" loop.

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


karthik
karthik 2015 年 2 月 4 日
clc
clear all
close all
j1=1;
for k=1:2
allR11=rand(1,10);
d6=length(allR11);
for op=1:d6
allR1_1(j1) = allR11(op)*rand;
%op=op+1;
j1=j1+1
end
end
This will work

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by