What Am I Missing? Newbie to MATLAB and not sure what to do.
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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")
%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
0 Comments
See Also
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!