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

1 回表示 (過去 30 日間)
Student 2022 年 2 月 22 日

I am trying to plot w, Pc, and F as functions of time following an iterative process but keep getting this error. How do I make them have the same number of elements?
clear all
close all
clc
hold on
for T = 1:1:101
t = (T-1)/5;
w(T) = 0.514 .* t; % Web Distance
Ab(T) = (2 .* pi) .* (((144-(3 + w).^2)) + ((3 + w) .* 20) + ((144-(3 + w).^2))) % Burn Area
Pc(T) = (1088000 .* Ab ./ (400000000 .* pi)).^(1/0.7); % Chamber Pressure
rb(T) = 0.4 .* Pc.^0.3; % Burn Radius
F(T) = Pc .* pi .* 8000000; % Thrust Force
if w > 9
break
else
continue
end
end
plot(w);
xlim([0 90])
ylim([0 10])
title('Web Distance vs. Time')
xlabel('Time (s)')
ylabel('Web Distance')
plot(Pc);
xlim([0 90])
ylim([0 5])
title('Chamber Pressure vs. Time')
xlabel('Time (s)')
ylabel('Chamber Pressure')
plot(F);
xlim([0 90])
ylim([0 10])
title('Thrust vs. Time')
xlabel('Time (s)')
ylabel('Thrust')
hold off
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Student 2022 年 2 月 22 日
How would I make that change?
DGM 2022 年 2 月 22 日
It's up to you to decide which elements you're trying to use. Decide which one you want and specify the appropriate index instead of the entire vector.

サインインしてコメントする。

### 採用された回答

Prateek Rai 2022 年 2 月 24 日
To my understanding, you want to plot w, Pc and F as functions of time follwing an interactive process.
You are getting an error because you are assigning array to a scalar quantity in line 8, line 9, line 10 and line 11 which causes error from 2nd iteration.
A possible workaround could be assigning the particular value of array (most proably the current value of array) to scalar quantity in above mentioned lines.
The code would look like:
clear all
close all
clc
hold on
for T = 1:1:101
t = (T-1)/5;
w(T) = 0.514 .* t % Web Distance
Ab(T) = (2 .* pi) .* (((144-(3 + w(T)).^2)) + ((3 + w(T)) .* 20) + ((144-(3 + w(T)).^2))) % Burn Area
Pc(T) = (1088000 .* Ab(T) ./ (400000000 .* pi)).^(1/0.7); % Chamber Pressure
rb(T) = 0.4 .* Pc(T).^0.3; % Burn Radius
F(T) = Pc(T) .* pi .* 8000000; % Thrust Force
if w > 9
break
else
continue
end
end
plot(w);
xlim([0 90])
ylim([0 10])
title('Web Distance vs. Time')
xlabel('Time (s)')
ylabel('Web Distance')
plot(Pc);
xlim([0 90])
ylim([0 5])
title('Chamber Pressure vs. Time')
xlabel('Time (s)')
ylabel('Chamber Pressure')
plot(F);
xlim([0 90])
ylim([0 10])
title('Thrust vs. Time')
xlabel('Time (s)')
ylabel('Thrust')
hold off

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by