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