Create a table that involves arrays
Show older comments
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 Comment
Connor Fehr
on 30 Apr 2021
Answers (1)
Atsushi Ueno
on 30 Apr 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 Comment
Connor Fehr
on 3 May 2021
Categories
Find more on Data Type Identification 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!