Please help me to put a for loop for vectors that increases number of rows with each loop
2 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am modelling a Particle Size Distribution using MATLAB which increases in the number of columns as chewing number increases.
So as a start, at chew 1, I have an input vector of X number of rows (these are the particle sizes) and 1 column (chew number 1), which was generated from a random Normal distribution. This is the initial number of particles. The output of my model is a new distribution, with a new number of rows. I will then use this output to become the next input of my model for chew 2, and the output for chew 2 (again a new number of rows) will be used as an input for the next chewing number.
Just a brief preview of my current code;
%Input
Chew_no=4; %This will be the number of columns for my input growing matrix
%When chew no 1, Dp=Dp %This is my first input
Dp=[4.74995832162336;4.78857686834444;4.81834297133678;4.81927711438771;4.83452623567326;4.83525188874587];
%Series of Calculations to get Dpnew
Dpnew(1)=[0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532;0.711929619334532];%This is my first output which will be the next input for the next chew/loop..
%When chew no 2, Dp=Dpnew(1)
%Series of Calculations to get Dpnew
Dpnew(2)=[]; %New vector of higher number of rows than Dpnew(1) in column 2
%When chew no 3, Dp=Dpnew(2);
% Series of calculations to get Dpnew
Dpnew(3)=[]; %New vector of higher number of rows than Dpnew(2) in column 3
%When chew no 3, Dp=Dpnew(3);
% Series of Calculations to get Dp new Dpnew(4)=[]; %New vector of higher number of rows than Dpnew(3) in column 4
%and so on...
My question is, how do I put a for loop inside the code as the number of rows increases with the loop? I keep getting errors such as 'Subscripted assignment dimension mismatch'
Any help is much appreciated!!
Cheers,
How
2 个评论
Walter Roberson
2018-4-11
How does this differ from your previous https://www.mathworks.com/matlabcentral/answers/393553-how-to-create-new-column-of-data-that-increases-number-of-rows-after-each-iteration-of-a-for-loop
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!