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 个评论
per isakson
per isakson 2020-5-25
In Matlab there is a function named, sum, and another named diff.
Ozan Mirzanli
Ozan Mirzanli 2020-5-25
编辑:Ozan Mirzanli 2020-5-25
thank you genius, I was clear enough that problematic part was about using loops.

请先登录,再进行评论。

回答(1 个)

Image Analyst
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by