how to make a matrix without hardcode?

Write a matlab function that has two scalar inputs and one output. The inputs represent the number of rows and columns of a matrix. Your function must use those inputs to first create a matrix of that size. You must do this without hardcoding any values. Then your function must modify that matrix so that all the elements are preserved, but in a 1-by-(m*n) array, where m is the number of rows, and n is the number of columns of your original matrix. Your function must output this array. Your function must work for any m x n matrix.
function[A]=ECE(row,column,q)
x=1:row;
y=1:column;
AB=x'*y;
if(q==1)
A=[1:(row*column)]
else
A=[1:(row*column)]
end
end

2 comentarios

Stephan
Stephan el 6 de Dic. de 2018
Please show us what you have tried so far.
Stephen23
Stephen23 el 6 de Dic. de 2018
Editada: Stephen23 el 6 de Dic. de 2018
  1. Although your title asks "how to make a matrix with hardcode?", your assignment actually states "You must do this without hardcoding any values". So, which is correct?
  2. You just copied your assignment here, without showing your own attempt or asking any specific question about something your have tried or read... are you just looking for someone to do your homework for you?

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 6 de Dic. de 2018
Editada: Jan el 6 de Dic. de 2018
function that has two scalar inputs - your function has 3 inputs yet:
function[A]=ECE(row,column,q)
Omit the useless "q".
x = 1:row;
y = 1:column;
AB = x' * y;
A nice idea. zeros(row, column) would work also, or rand(), ones(), etc.
modify that matrix - With creating A you do not "modify" the matrix. Use reshape instead.
Your code does not contain any hardcoded values, so the question is solved already.

Categorías

Preguntada:

el 6 de Dic. de 2018

Editada:

Jan
el 6 de Dic. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by