Error message with arrays

1 view (last 30 days)
Iver Brekken
Iver Brekken on 26 Jan 2022
Answered: Alan Stevens on 26 Jan 2022
clear all
clc
close all
h = [2:20:220];
t_a = 293;
t_s = [];
q_flux = 800;
n = length(h);
for i = 1:n
t_s = q_flux./h+t_a;
y(i) = t_s;
i = i+1;
end
plot(h,y)
When running this i obtain the following error message:
Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in a2 (line 13)
y(i) = t_s;
what can i do different?

Answers (1)

Alan Stevens
Alan Stevens on 26 Jan 2022
You only need
h = [2:20:220];
t_a = 293;
q_flux = 800;
n = length(h);
y = q_flux./h+t_a;
i = i+1;
plot(h,y)

Community Treasure Hunt

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

Start Hunting!