Effacer les filtres
Effacer les filtres

3 × 3 hit

2 vues (au cours des 30 derniers jours)
Rusel Ibrahim
Rusel Ibrahim le 6 Juin 2021
Commenté : Steven Lord le 6 Juin 2021
Q1) write matlab mfile program to input 3x3 A matrix and then call a function that multiply each elements of odd columns from this matrix by 4 then display the result after execute the function?
  1 commentaire
Steven Lord
Steven Lord le 6 Juin 2021
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Connectez-vous pour commenter.

Réponses (1)

Manas Minnoor
Manas Minnoor le 6 Juin 2021
Hi Rusel,
Assuming you want to input the numbers one by one, you may use nested for loops along with the input function, whose documentation are linked below.
To multiply odd columns by 4, you may again use nested for loops along with the colon operator to access only odd columns.
Hope this helps.
  1 commentaire
DGM
DGM le 6 Juin 2021
select odd columns of A:
A(:,1:2:end);
select even columns of A:
A(:,2:2:end);
no loops needed.
Requiring users to manually input everything anew every time a script is run is just plain bad in my opinion. It's a waste of the user's time and concentration and only promotes errors, but I guess the people writing homework assignments love it. I don't doubt that's the intended way.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by