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 个)
Atsushi Ueno
2021-4-30
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!