I don't understand what does the question ask!

1 visualización (últimos 30 días)
Ozan Mirzanli
Ozan Mirzanli el 25 de Mayo de 2020
Respondida: Image Analyst el 25 de Mayo de 2020
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 comentarios
per isakson
per isakson el 25 de Mayo de 2020
In Matlab there is a function named, sum, and another named diff.
Ozan Mirzanli
Ozan Mirzanli el 25 de Mayo de 2020
Editada: Ozan Mirzanli el 25 de Mayo de 2020
thank you genius, I was clear enough that problematic part was about using loops.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 25 de Mayo de 2020
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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by