Reputation: 5
im trying to make a function that lets you chose rows and columns and return that value and print a graph. I'm new at matlab, but here's what i have been writing.
function [sorted] = createMatrix()
rows = input('rows?');
columns = input('columns?');
unsorted = randi(100,rows,columns);
sorted = sort(unsorted);
This is the first function that create and sort the matrix, it works just fine, tho its not returning any value as output i think, "workspace" have one line named "ans" with my matrix, tho not the name i wanted it to have. I dont have any problem with the second function that shows the 3DGraph!
So the big problem that i think i have is the output as a matrix!
Thank you!
Upvotes: 0
Views: 34
Reputation: 29094
The function is written correctly.
function [sorted] = createMatrix()
rows = input('rows?');
columns = input('columns?');
unsorted = randi(100,rows,columns);
sorted = sort(unsorted);
I think you are calling the function as createMatrix(), that is why you are having matrix stored as ans.
To solve this:
theNameYouWant = createMatrix();
Upvotes: 1