フィルターのクリア

"Using MATLAB Write a function that Calculates the overall sum of the elements in each row of a Matrix and also shows on the screen (Not: prints the sum of only the positive numbers from each row)" How can I apply the note to the code?

2 ビュー (過去 30 日間)
I have a question like "Using MATLAB Write a function that Calculates the overall sum of the elements in each row of a Matrix and also shows on the screen (Not: prints the sum of only the positive numbers from each row)" and I wrote the code but I did not understand how to apply note to the code.
row = input('Enter number of rows: ');
col = input('Enter number of columns: ');
A = zeros(row+1,col+1);
for i = 1:row
for j = 1:col
str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': '];
A(i,j) = input(str);
end
end
fprintf('
A;
A(end,1:col) = sum(A(1:row,1:col),1);
A(1:row,end) = sum(A(1:row,1:col),2);
  2 件のコメント
Rik
Rik 2021 年 1 月 5 日
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable. You should also probably fix the syntax errors.

サインインしてコメントする。

採用された回答

Daniel Catton
Daniel Catton 2021 年 1 月 5 日
This is my understanding of the question:
A = rand(15,13); %Can set to whatever matrix you wish
[row,col] = size(A); %Counts how many rows and cols in the matrix
b = 0;
B = zeros(row,1); %Preallocates B for speed (probably not necessary in this case but good practice to do so)
for i = 1:row
for j = 1:col
a = A(i,j); %Goes through each element in the row
if a > 0
b = b+a; %If a is positive then it is added to b
end
end
B(i,1) = b; %b is displayed in the matrix B
b = 0;
end
  4 件のコメント
Rik
Rik 2021 年 1 月 5 日
@Daniel, please refrain from giving complete solutions to homework problems. That only encourages cheating and means that you will be asked to do their homework next time as well.
Quietuss Yuroka
Quietuss Yuroka 2021 年 1 月 5 日
That is not I was trying to do actually. I had just start matlab and just trying to understand question. My apologies if I misunderstood.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by