Info

This question is closed. Reopen it to edit or answer.

Can sparse matrix be used in place of zero matrix for space allocation in for loop?

1 view (last 30 days)
Hi mathworks commnunities,
I developed an optimization model in matlab but i observed the memory allocation of the model is much which slow down the computational time.
My question is if it is possible to use sparse matrix in place of zero matrix for space allocation in for loop statement in order to reduce memory usage?
Part of the code is:
% Wind Generation Constraint
Pwind=zeros(8760,1); % is possible to change to sparse( 8760,1) without altering the duty of for loop?
for ll = 1:nHours
if WindVelocity(ll)<Vci
Pwind(ll)=0;
elseif WindVelocity(ll)>Vco
Pwind(ll)=0;
elseif Vr<WindVelocity(ll)<Vco
Pwind(ll)=20;
elseif Vci<WindVelocity(ll)<Vr
Pwind(ll)=20*((WindVelocity(ll)-Vci)/(Vr-Vci));
end
end
Thanks,
Mic

Answers (0)

Community Treasure Hunt

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

Start Hunting!