Write a script to create a matrix B equal to A, but with its last column equal set to 0.
5 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
chicken vector
on 7 Apr 2023
Edited: chicken vector
on 7 Apr 2023
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 Comment
John D'Errico
on 7 Apr 2023
Edited: John D'Errico
on 7 Apr 2023
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.
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!