Clear Filters
Clear Filters

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

4 views (last 30 days)
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 Comments
DGM
DGM on 22 Feb 2022
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.

Sign in to comment.

Accepted Answer

Prateek Rai
Prateek Rai on 24 Feb 2022
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

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!