필터 지우기
필터 지우기

Unable to perform assignment because the left and right sides have a different number of elements

조회 수: 2 (최근 30일)
I have the follwing matlab code. After excecuting it, error is displayed as "Unable to perform assignment because the left and right sides have a different number of elements." Kindly help me out.
k12=200;
k34=500;
K=zeros(4,4);
a=2:0.02:9;
b=1:length(a);
kc(b)=2:0.02:9;
for b=1:length(a)
kc(b)=2:0.02:9;
K(b)=[k12 -k12 0 0;-k12 kc(b)+k12 -kc(b) 0;0 -kc(b) k34+kc(b) -k34;0 0 -k34 k34];
end

답변 (1개)

Image Analyst
Image Analyst 2021년 11월 2일
kc(b) is a single element because b is a single number between 1 and length(a).
2:0.02:9 is a 351 long row vector, NOT a single number.
You cannot stuff 351 numbers into an element meant to take only one number.
K(b) is a single element because b is a single number between 1 and length(a).
[k12 -k12 0 0;-k12 kc(b)+k12 -kc(b) 0;0 -kc(b) k34+kc(b) -k34;0 0 -k34 k34]; is a 4-by-4 matrix, NOT a single number.
You cannot stuff a 4x4 matrix into an element meant to take only one number.
  댓글 수: 6
venkatesu u
venkatesu u 2021년 11월 4일
Hi
I need to work with all of the values. I tried in another way with the following code.
clear all
clc
kc=[1 2 3 4 5 6 7 8 9 0];
k12=200;
k34=300;
new1=1:1:10;
for h1=1:length(new1);
for l1=1:length(new1);
K(h1,l1)=[k12 -k12 0 0;-k12 kc(h1,l1)+k12 -kc(h1,l1) 0;0 -kc(h1,l1) k34+kc(h1,l1) -k34;0 0 -k34 k34];
end
end
But it shows the following error after execution in MATLAB.
"Unable to perform assignment because the indices on the left side are not compatible with the size of the right side"
Kindly help me with this.
Image Analyst
Image Analyst 2021년 11월 4일
Same problem and same question. You're trying to stick a 4x4 matrix into a location that can hold only one value. I don't know why you are trying to do that other than you saying you think you need to. But it's not allowed.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by