What Am I Missing? Newbie to MATLAB and not sure what to do.

1 view (last 30 days)
I'm pretty new and not sure exactly how to fix this problem.
%declaring variables
V=zeros(5,5);
R=[16.4e-9 17.2e-9 28.2e-9 100e-9];%resistivity of material (silver, copper, aluminium, and iron)
A=[1.31e-6 517.63e-9 204.73e-9 80.98e-9 32.03e-9];%AWG Area of 16, 20, 24, 28, and 32. in m^2
for(y=1:1:5)
for(x=1:1:5)
V(y,x)=(0.1*((R(y)*1000)/(A(x))));%calculation of volatage in Volts(V)
%Given: I=0.1A, Length= 10Km = 10000m
end
end
sol=V<100; %Check the volatge is less than 100V
Com=[];
for row=1:5 %for loop in order to output a matrix with the coordinates where voltage is less than 100V.
for col=1:5
if sol(row,col)==1
Com=[Com;row,col];
end
end
end
[r,c]=size(Com);
fprintf("The following combination with volatage loss of less than 100V is:\n")
for m=1:1:r %for loop to output material name and AWG# base on the coordinates system.
m_id=Com(m,1);
a_id=Com(m,2);
if m_id==1
fprintf('Silver and ');
elseif m_id==2
fprintf('Copper and ');
elseif m_id==3
fprintf('Aluminium and ');
else
fprintf('Iron and ');
end
if a_id==1
fprintf('AWG 16\n')
elseif a_id==2
fprintf('AWG 20\n')
elseif a_id==3
fprintf('AWG 24\n')
elseif a_id==4
fprintf('AWG 28\n')
else
fprintf('AWG 32\n')
end
end

Answers (1)

Arif Hoq
Arif Hoq on 10 Nov 2022
Edited: Arif Hoq on 10 Nov 2022
Variable R is a row vector of 4 elements. But you defined indices up to 5. That's why you are getting an error.
V=zeros(4,5);
R=[16.4e-9 17.2e-9 28.2e-9 100e-9];%resistivity of material (silver, copper, aluminium, and iron)
A=[1.31e-6 517.63e-9 204.73e-9 80.98e-9 32.03e-9];%AWG Area of 16, 20, 24, 28, and 32. in m^2
for i=1:4
for j=1:5
V(i,j)=0.1*(R(i)*1000/A(j));%calculation of volatage in Volts(V)
%Given: I=0.1A, Length= 10Km = 10000m
end
end
sol=V<100; %Check the volatge is less than 100V
Com=[];
%for loop in order to output a matrix with the coordinates where voltage is less than 100V.
for row=1:4
for col=1:5
if sol(row,col)==1
Com=[Com;row,col];
end
end
end
[r,c]=size(Com);
fprintf("The following combination with volatage loss of less than 100V is:\n")
The following combination with volatage loss of less than 100V is:
%for loop to output material name and AWG# base on the coordinates system.
for m=1:1:r
m_id=Com(m,1);
a_id=Com(m,2);
if m_id==1
fprintf('Silver and ');
elseif m_id==2
fprintf('Copper and ');
elseif m_id==3
fprintf('Aluminium and ');
else
fprintf('Iron and ');
end
if a_id==1
fprintf('AWG 16\n')
elseif a_id==2
fprintf('AWG 20\n')
elseif a_id==3
fprintf('AWG 24\n')
elseif a_id==4
fprintf('AWG 28\n')
else
fprintf('AWG 32\n')
end
end
Silver and
AWG 16
Silver and
AWG 20
Silver and
AWG 24
Silver and
AWG 28
Silver and
AWG 32
Copper and
AWG 16
Copper and
AWG 20
Copper and
AWG 24
Copper and
AWG 28
Copper and
AWG 32
Aluminium and
AWG 16
Aluminium and
AWG 20
Aluminium and
AWG 24
Aluminium and
AWG 28
Aluminium and
AWG 32
Iron and
AWG 16
Iron and
AWG 20
Iron and
AWG 24

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by