In an assignment A(I) = B, the number of elements in B and I must be the same. this is the error i am getting

hi i am trying to assign few values like this "for k=1:1:12 rh(k)=[200 300 400 400 900 1300 1350 1300 1000 700 650 350]; end"
the error i am getting is In an assignment A(I) = B, the number of elements in B and I must be the same. i have to assign rh(1)=200, rh(2)= 300 and so on till rh(12)=350. can anyone please help me?

 采纳的回答

You don't need a for loop for that
rh=[200 300 400 400 900 1300 1350 1300 1000 700 650 350];

7 个评论

thanks for the answer. but still i have to assign because, rh( required heat) has 12 values one for each month. i have to compare this each rh to another value and have to place an if statement based on the comparison. hope you understood the problem
the values which i have given above are the heat requirement for each month. but the heat generated will be varying. if the heat generated is more it's not a problem but if it is less i have to set up a boiler. what i was thinking was if i assign these values to k(1 to 12) i can write the condition like ' if rh(k)>hg'.
forget what i have told before. can you please tell me how can i code to select maximum value of the matrix rh=[200 300 400 400 900 1300 1350 1300 1000 700 650 350];

请先登录,再进行评论。

更多回答(1 个)

Hi Trilochan,
MATLAB is a powerful resource for matrix indexing operations. Rather than loop through and assign each element of the array to each element of variable 'rh' why don't you try the following:
rh(1:12) = [200 300 400 400 900 1300 1350 1300 1000 700 650 350];
or alternatively if variable 'rh' only has 12 elements, you can get rid of the (1:12) indexing and instead simply use:
rh = [200 300 400 400 900 1300 1350 1300 1000 700 650 350];
~Zack

1 个评论

thanks for the answer. but still i have to assign because, rh( required heat) has 12 values one for each month. i have to compare this each rh to another value and have to place an if statement based on the comparison. hope you understood the problem

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by