3 × 3 hit

4 visualizzazioni (ultimi 30 giorni)
Rusel Ibrahim
Rusel Ibrahim il 6 Giu 2021
Commentato: Steven Lord il 6 Giu 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 Commento
Steven Lord
Steven Lord il 6 Giu 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.

Accedi per commentare.

Risposte (1)

Manas Minnoor
Manas Minnoor il 6 Giu 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 Commento
DGM
DGM il 6 Giu 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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti


Release

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by