Creating a 365x24 matrix using for and if
1 view (last 30 days)
Show older comments
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 Comment
Stephen23
on 23 Jul 2019
Assuming that COSMY2013 has the same size:
COSMY2014 = COSMY2013;
COSMY2014(:) = -9999
Accepted Answer
Rik
on 23 Jul 2019
You're confusing while and for.
But you need neither:
COSMY2014=-9999*ones(365,24);
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!