Unable to perform assignment because the left and right sides have a different number of elements.
1,577 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to solve this problem in many ways but there is still the error like in the tittle
Script:
n1=1.35
y=0:0.01:0.8;
T3=zeros(length(y),1);
for a=1:length(y)
y(a)=y(a)/n1;
T3(a)=[1 y(a); 0 1];
end
1 件のコメント
Hector
2023 年 3 月 21 日
編集済み: Steven Lord
2023 年 3 月 21 日
How about assign y(i) + [(3*(Q/A).*sind(t).^2)-(Q/A)].*0.5 (size 21 x 1) to y(i) (size 1) with different number of elements? It was effective in my situation when I was in [SL: removed link that from the URL looked like spam] You will soon find the useful way. Good luck!
採用された回答
Steven Lord
2019 年 1 月 9 日
The left side of this line of code refers to 1 element of T3. The right side refers to a 4 element matrix.
T3(a)=[1 y(a); 0 1];
You can't stuff a 4 element matrix into 1 element of a vector. It works about as well as stuffing 4 eggs into one of the cups in an egg carton without breaking any.
You could create a 3-dimensional array where each page of the array contains one of these matrices or you could create a cell array.
0 件のコメント
その他の回答 (1 件)
Ali Syed
2021 年 1 月 30 日
編集済み: DGM
2023 年 2 月 13 日
The notion to use for making both sides sizes equal to each other will be as follows in the example:
% It is MARTIX_NAME( :, :, i) = MATRIX; %Where the i is the incremental chnage to go to the next value
B = [0, 1, 0, pi, pi, pi/2, 0, 0, 1, pi/2, pi, 1, 1]
RANDOM_Var = ones (4,4)
for i=1:13
T = B(:, i)
C = cos(T)
S = sin(T)
k = [C, S, C*S, S; C, C, S, S; C*S, C*S, C^2, S^2; C^2, S^2, S, C]
RANDOM_Var(:, :, i) = k
end
5 件のコメント
Ahmad
2024 年 2 月 6 日
編集済み: Walter Roberson
2024 年 2 月 7 日
I'm encountering the same problem in line 12 of my code where I'm trying to plot a piecewise continuous graph in its discrete time form. I'm new to Matlab and I'm trying to learn, any help would be greatly appreciated as I honestly don't know what's wrong or how to solve it. I also have the question which I can add as well if it helps.
T=4*pi;
i=10;
h=T/i;
a=1;
tcs=0;
tcm=T/2;
tce=T;
for ts1=tcs:h:tcm
t(a)=ts1;
t1(a)=ts1-tcs;
y(a)=1-exp(-t1);
a=a+1;
ts1=ts1+h;
end
for ts2=tcm:h:tce
t(a)=ts2;
t1(a)=ts2-tcm;
y(a)=exp(-t2);
a=a+1;
ts2=ts2+h;
end
plot(t,y)
Stephen23
2024 年 2 月 7 日
One this line you are trying to force a vector into a scalar location:
y(a)=1-exp(-t1);
On the first loop iteration that will work because t1 is also scalar. But after that you will get an assignment error. The solution is exactly the same as with the other discussions on this thread: you need to slect the same number of elements on the RHS as you are trying to assign on the LHS of that assignment:
y(a)=1-exp(-t1(a));
% ^^^
Your code has some other bugs.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!