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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Oct. de 2013
You don't need a for loop for that
rh=[200 300 400 400 900 1300 1350 1300 1000 700 650 350];
  7 comentarios

Iniciar sesión para comentar.

Más respuestas (1)

Zack Peters
Zack Peters el 24 de Oct. de 2013
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 comentario
trilochan
trilochan el 25 de Oct. de 2013
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

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by