3 × 3 hit

4 visualizaciones (últimos 30 días)
Rusel Ibrahim
Rusel Ibrahim el 6 de Jun. de 2021
Comentada: Steven Lord el 6 de Jun. de 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 comentario
Steven Lord
Steven Lord el 6 de Jun. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Manas Minnoor
Manas Minnoor el 6 de Jun. de 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 comentario
DGM
DGM el 6 de Jun. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by