MATLAB Answers

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

2 views (last 30 days)
Yulia M
Yulia M on 8 Nov 2019
Commented: Yulia M on 11 Nov 2019
Hi ,
I am new to MATLAB, I need help with this problem please help!
I'm trying to do this operation.
A is 256 * 1 double
B is 18 * 1 complex double
I am trying to do
A (17: 240) = B;
But I am getting this error! what might be the reason?
"In assignment A (I) = B, the number of elements in B and I must be the same."

  3 Comments

KSSV
KSSV on 8 Nov 2019
YOu see from 17:240 it makes 224 indices.....so you have to input an array of size 1*224. How you think you can initilaize them?
Stephen Cobeldick
Stephen Cobeldick on 8 Nov 2019
"But I am getting this error! what might be the reason?"
You are trying to assign 18 elements to 224 elements.
On the LHS you use indexing to refer to 224 elements of the array A.
On the RHS you have an array with 18 elements.
Given that the RHS only has 18 elements, what do you expect the remaining 206 elements to be filled with? As the error message states, both the LHS and the RHS need to refer to the same number of elements.

Sign in to comment.

Accepted Answer

Shubham Gupta
Shubham Gupta on 8 Nov 2019
Your:
A(17:240) % is a vector of 224 elements ((240-17+1)x1)
while
B % is a vector of 18 elements (18x1)
that's why you are getting the error

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.