Please help me to put a for loop for vectors that increases number of rows with each loop

2 Ansichten (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 11 Apr. 2018
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
Syahmeer How
Syahmeer How am 11 Apr. 2018
Hi Walter, it is the same question except that the current one is a simpler version of my older one. Just thought I should simplify the codes to make it easier for people to understand :) I should probably delete my previous post. Do you have an tips on how should I approach this problem?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

KSSV
KSSV am 11 Apr. 2018
REad about Cell. You can save the data into a cell.
  1 Kommentar
Syahmeer How
Syahmeer How am 11 Apr. 2018
Thanks for the reply KSSV. I actually tried Cell before but it takes ages (kept running for hours and didn’t stop) to run it. Do you know if there is another approach to solve this other than using cell?
Cheers

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Parallel Computing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by