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

2 次查看(过去 30 天)
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 个评论
DGM
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
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by