how to make a matrix without hardcode?
Show older comments
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 Comments
Stephan
on 6 Dec 2018
Please show us what you have tried so far.
- 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?
- 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?
Answers (1)
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.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!