Create a table that involves arrays

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

Connor Fehr
Connor Fehr 2021년 4월 30일
rh = input('Please enter the height of the ramp (feet): ')

댓글을 달려면 로그인하십시오.

답변 (1개)

Atsushi Ueno
Atsushi Ueno 2021년 4월 30일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 4월 30일

댓글:

2021년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by