Create a table that involves arrays
Afficher commentaires plus anciens
I created 'Degrees' which has one number per colum and has 91 colums. I used this to calculate 'ma' which has the same amount of numbers in the same order. I repeat this one more time. Then I am trying to make a table from scratch but determining how many colums there are using a for loop to plot each varible. Some reason I can not get it to work and looking for help.
Here is my code...
Degrees = [1:1:90]
%Calculating the mechanical advantage using the degrees
ma = 1./sind(Degrees)
%Calculating the length of ramp needed to acomplish the degrees and height
%needed.
%-------------------------rl = rh.*sqrt((ma+1).*(ma-1));
rl = rh.*cotd(Degrees)
%Prints the header for the table being created.
fprintf('-------------------------------------------------------------------------\n');
fprintf('\t Degrees (°) \t Length (feet) \t Height (feet) \t Mechanical Advantage \n');
fprintf('-------------------------------------------------------------------------\n');
%Determining the size of the file.
%[~,numRows] = size(Degrees);
numRows = size(Degrees,2)
%Prints the calculations for evry row in the file and printing them into a
%table.
for i = [1:1:numRows]
fprintf('%9.2f %8.2f %6.2f %7.2f \n',Degrees(i,2),rl(i,2),rh,ma(i,2));
end
1 commentaire
Connor Fehr
le 30 Avr 2021
Réponses (1)
Atsushi Ueno
le 30 Avr 2021
Degrees, rl, and ma are vectors. They are not matrices.
fprintf('%9.2f %8.2f %6.2f %7.2f \n',Degrees(i,2),rl(i,2),rh,ma(i,2));
shall be
fprintf('%9.2f %8.2f %6.2f %7.2f \n',Degrees(i),rl(i),rh,ma(i));
Also, rh is not defined in your code.
1 commentaire
Connor Fehr
le 3 Mai 2021
Catégories
En savoir plus sur Elementary Math dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!