Creating a 365x24 matrix using for and if
23 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2019 年 7 月 23 日
Assuming that COSMY2013 has the same size:
COSMY2014 = COSMY2013;
COSMY2014(:) = -9999
採用された回答
Rik
2019 年 7 月 23 日
You're confusing while and for.
But you need neither:
COSMY2014=-9999*ones(365,24);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!