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

11 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

chicken vector
chicken vector le 7 Avr 2023
Modifié(e) : chicken vector le 7 Avr 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 commentaire
John D'Errico
John D'Errico le 7 Avr 2023
Modifié(e) : John D'Errico le 7 Avr 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by