no input, two output function

9 Ansichten (letzte 30 Tage)
furcifer
furcifer am 5 Nov. 2018
Kommentiert: madhan ravi am 12 Nov. 2018
The first part of this assignment is to create a function with no inputs and two outputs. The 15x1 matrices are X and Y so I've got
function [X,Y] = myfunct()
X=[1;2;3 etc]
Y=[1;2;3 etc]
plot(X,Y,'.b')
end
If I run the function, the only thing that appears in the workspace is ans. Is this because they are local variables? How do I assign them to memory? Because the next part of the assignment is to create a function with a "for" loop that adds or multiplies elements of the arrays. The inputs are X and Y, but since they aren't defined I think it's screwing up my code. I believe we are supposed to load the first function so the next function (two input two output) can grab the X and Y from memory, perform the operations and output m and b (this is for a linear regression). (fyi-We're not supposed to use the 'sum' function, gotta use loops)
eta: And how do I create a single column vector with 1 to n elements? Rows is easy but I couldn't figure out a column.

Akzeptierte Antwort

madhan ravi
madhan ravi am 5 Nov. 2018
[X,Y] = myfunct % try calling it with two outputs
function [X,Y] = myfunct
X=[1;2;3];
Y=[1;2;3];
plot(X,Y,'.b')
end
  10 Kommentare
furcifer
furcifer am 11 Nov. 2018
Hi All, thanks for the help. I went through my code and finally got it to do what I wanted. It seems I was calling for the previous function outside the new function and that was screwing it up. Lesson learned, I hope. :)
madhan ravi
madhan ravi am 12 Nov. 2018
You can show your thanks to everyone by accepting the answer

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by