Write a script to create a matrix B equal to A, but with its last column equal set to 0.

5 次查看(过去 30 天)
Can someone help with a hint of this question using MATLAB?
Write a script to create a matrix B equal to A, but with its last column equal set to 0.

采纳的回答

chicken vector
chicken vector 2023-4-7
编辑:chicken vector 2023-4-7
I suppose you want to limit your case to bi-dimensional arrays.
You can create a function which works for every matrix
function A = createCopyWithNullLastColumn(A)
% Change values of last column :
A(:,end) = 0;
end
Or go with the script:
% Create random matrix <A>:
A = rand(randi([1,10]), randi([1,10]));
% Create a copy <B> of <A>:
B = A;
% Set last column of <B> equal to <0>:
B(:,end) = 0;
  1 个评论
John D'Errico
John D'Errico 2023-4-7
编辑:John D'Errico 2023-4-7
Please don't do obvious homework assignments for students. This never helps the student, who learns nothing more than they can find someone willing to do their work for them, if they only plead sadly enough.
It does not help the site, since it convinces that student to continue to post their homework assignments, with no effort made.
Worse, it actively hurts the site, because then it convinces other students they have the right to post their homework assignments too. You then help to turn answers into a site where nothing is seen except for students angrily demanding that we do their homework for them, and do it quickly.
If you feel compelled to help, then offer some guidance. Push them in the right directino. Here, you might have suggested they create a smaller random matrix, and then append zeros, or something like that, but NOT write the code for them.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by