Assigning outputs variable names

11 views (last 30 days)
I'm using the function findchangepts, which outputs 2 numerical values for me. I'd like to use these values and manipulate them further. How can I assign them separate variable names?
Thank you!
SamplNum = findchangepts(SensV, 'MaxNumChanges', 2);
% code
which gives
SamplNum =
So I'd like to assign both of those sample numbers a variable in order to manipulate them.
Thanks for your help, sorry if this is a simple question/answer, I'm new to Matlab!
Stephen23 on 27 Jul 2018
If you really want to create two variables from the first two elements of the output vector, then use indexing:
SamplNum = findchangepts(SensV, 'MaxNumChanges', 2);
A = SamplNum(1)
B = SamplNum(2)
Note that this is not a general solution: the best solution would be to leave the data in the vector, where is easy to process, no matter how many elements it contains.
Basic MATLAB concepts, like how to use indexing and how to define variables, are explained in the introductory tutorials:

Sign in to comment.

Accepted Answer

Philipp Heinirch
Philipp Heinirch on 27 Jul 2018
I am not sure how the function is working, but you could simply do
or you do
[Variable_1, Variable_2] = findchangepts(SensV, 'MaxNumChanges', 2);
and adapt the code in-between.
Philipp Heinirch
Philipp Heinirch on 30 Jul 2018
Oh yeah, you are right. did not properly pay attention to this. My bad.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by