Dynamic arrays error message
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Abner Ojeda
il 17 Mag 2020
Commentato: Abner Ojeda
il 19 Mag 2020
Hey everyone,
I have many variables in my code that increase their size with a for bucle, and I've been realized of the code assistance adverticement. I read the advice and try to apply it, but I couldn't solve it. I am trying to solve ir because it's going to be and extens code and I'm try to not expend many resources in that kind of things. (I know that my code isn't optimum, jaja) but that's really bugging me.
Thanks for your help and have a great day.
P.S: This is the suggestion "Variable 'name of the variable' appers to change size on every loop iteration"
Dhx=[];
Dgx=[];
Dfx=[];
for s=x(1:end)
gh= diff(hx, (s));
gg= diff(gx, (s));
gf= diff(func, (s));
Dfx=[Dfx, gf];
Dhx=[Dhx, gh];
Dgx=[Dgx, gg];
end
0 Commenti
Risposta accettata
Ameer Hamza
il 17 Mag 2020
Modificato: Ameer Hamza
il 17 Mag 2020
Try changing to something like this
Dhx=cell(1,numel(x));
Dgx=cell(1,numel(x));
Dfx=cell(1,numel(x));
for i=1:numel(x)
Dhx{i} = diff(hx, x(i));
Dgx{i} = diff(gx, x(i));
Dfx{i} = diff(func, x(i));
end
Dhx = [Dhx{:}];
Dgx = [Dhx{:}];
Dfx = [Dhx{:}];
9 Commenti
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!