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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Rik
Rik am 23 Jul. 2019

1 Stimme

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

1 Kommentar

Fe Mav
Fe Mav am 23 Jul. 2019
Thank you very much for the quick answer and the smart solution!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 23 Jul. 2019

Kommentiert:

am 23 Jul. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by