I don't understand what does the question ask!
1 次查看(过去 30 天)
显示 更早的评论
Write a Matlab script to create a random integer matrix with elements between -30 and 30. The size of the matrix must first be read from user input. Use loops to get the sum of each row. Next you will find the differences between all pairs of these sums. Write these differences in a "myout.txt" file, such as "the difference between the totals of lines 1 and 2 is xxx.yyy".
to solve the question,
I really didn't understand what should the sizes of matrix be so i decided it myself to be axb. And I did not understand what does "the size of the matrix must first be read from user input" mean, but i thought:
a=input('Enter the size of rows:');
b=input('Enter the size of columns:');
A=randi([-30 30],a,b)
Then I wanted to use for loop to calculate sum of each row but unfortunately I can't figure it out. I guess the differences between pairs of these sums should be calculated with for loops as well. I've tried to understand these loops by YouTube videos and MATLAB tutorials but I just couldn't. I also did not understand the "writing differences in a "myout.txt" file. I mean should I send two different files to the teacher? (One for programm and the other one is myout.txt) I know it may seem child's play to you but i really am beginner :)
2 个评论
回答(1 个)
Image Analyst
2020-5-25
Hint:
a=input('Enter the size of rows:');
b=input('Enter the size of columns:');
A=randi([-30 30],a,b)
for row = 1 : a
theRowSums(row) = sum(A(row,:))
end
dr = diff(
fid = fopen(
fprintf(
fclose(
Try to finish it.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!