Creating a 365x24 matrix using for and if

Hi!
I'm trying to create a numeric matrix. Every row is a day of the year and every collumn is an hour of the day, so the matrix's size is going to be 365x24.
i need all the sells to have the same value (-9999) and I need to to this using a loop in order to save time.
Here's what I've typed so far.
COSMY2014=zeros(size(COSMY2013));
i=1;
j=1;
for i < 366
for j < 25
if COSMY2014(i,j)=0
COSMY2014(i,j)=-9999;
end
j=j+1;
end
i=i+1;
end
I have created a matrix with the correct size but every cell's value is 0. What I'm trying to do in this piece of code is change every value to -9999 but when I run it nothing happens. I cannot find errors in the logic so I assume I've made mistakes in the syntax.
I really appreciate any help you can give me!

1 Commento

Assuming that COSMY2013 has the same size:
COSMY2014 = COSMY2013;
COSMY2014(:) = -9999

Accedi per commentare.

 Risposta accettata

You're confusing while and for.
But you need neither:
COSMY2014=-9999*ones(365,24);

1 Commento

Thank you very much for the quick answer and the smart solution!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 23 Lug 2019

Commentato:

il 23 Lug 2019

Community Treasure Hunt

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

Start Hunting!

Translated by