adding values to the same column
2 次查看(过去 30 天)
显示 更早的评论
hi there, I have a matlab question. Ok for example, I have 2 array of 1x350 each, one gives the information of mixture fraction, and the other one gives the information of temperature. For example,
Mix Frac 0.1 0.22 0.32 0.32 0.5 0.2 0.21 0.23
Temp 300 1200 580 560 1200 1320 1500 1360
What I want to do is to find the mixture fraction of a range of 0.19-0.21, and at the same time gives me the information of the temperature for that mixture fraction. So for example from the above ‘array’, it will create a new variable like below which only gives me the information of the temperature that in the range of the mixture fraction I asked….
Mix Frac 0.2 0.21
Temp 1320 1500
so i have got an answer for this, which it can be found by
xnMix_frac = xnMix_frac(:);
xnTemp = xnTemp(:);
t = xnMix_frac >= .19 & xnMix_frac <= .21;
out = [xnMix_frac(t), xnTemp(t)];
however, i am running a loop, so the 'out' will get overwritten. as in each loop, the number of xnMix_frac that satisfies the criteria is not the same, so i couldnt use the 'out=[out i+rand]'.
i was wondering if for every loop, it is possible to keep adding the data on the same column of 'out' in the new row and so on?
for example, the first two mix frac and temp value is from the first loop, and the last four from the second loop and so on?
Mix Frac 0.2 0.21 0.2 0.19 0.2 0.2
Temp 1320 1500 1300 1300 1450 1700
thanks!
0 个评论
采纳的回答
James Tursa
2016-7-13
编辑:James Tursa
2016-7-13
If the loop isn't too big, you could just append it and dynamically increase the size of out in the loop. E.g.,
out = []; % <-- prior to the start of the loop
:
out = [out; xnMix_frac(t), xnTemp(t)]; % <-- in the loop
But if the loop could be large, then maybe save all of the loop iteration out's in a cell array and then concatenate the cell array at the end of the loop. E.g.
out{loop_index} = [xnMix_frac(t), xnTemp(t)]; % <-- inside the loop
:
out = vertcat(out{:}); % <-- after the loop is done
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!