In an assignment A(I) = B, the number of elements in B and I must be the same.

1 回表示 (過去 30 日間)
Saleem Sarwar
Saleem Sarwar 2015 年 10 月 2 日
回答済み: Lessmann 2015 年 10 月 2 日
I need to compute runoff for 2 rainfall conditions
1. If rainfall > 5, then runoff = 1000/CN -10;
2. otherwise Runoff = (Rainfall -0.2 (1000/CN -10))^2 / (Rainfall + 0.80* (1000/CN -10)
My code is as follow
clear
>> Rainfall = randi(10,10,1);
>> CN = randi( 25,10,1);
>> idx = Rainfall > 5;
>> Runoff =size(Rainfall,1);
>> Runoff = zeros(Runoff,1);
>> Runoff(idx)= 1000/CN -10;
Runoff(~idx) = (Rainfall(~idx) - 0.2 * (1000/CN -10)^2)./Rainfall(~idx) + 0.8 *(1000/CN -10);
I am getting the following error when running the 1st condition
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Could any body help to solve this issue? I am not very familiar with matlab and trying to write script for runoff calculation using Soil Moisture Condition. Thanks and regards, Saleem
  1 件のコメント
per isakson
per isakson 2015 年 10 月 2 日
Readable questions and responses to comments increases the chance to get a useful answer. This time I formatted your text.

サインインしてコメントする。

採用された回答

Lessmann
Lessmann 2015 年 10 月 2 日
Hi,
your problem is, that the dimensions of Rainfall and CN don't match. Use the the index idx or ~idx on CN. Also the operators in the last line need tweaking to work elementwise.
Here are the changed lines:
Runoff(idx)= 1000/CN(idx) -10;
Runoff(~idx) = (Rainfall(~idx) - 0.2 * (1000./CN(~idx) -10).^2)./Rainfall(~idx) + 0.8 *(1000./CN(~idx) -10);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by