Looking for a matrix, and if there, adding to the end of it
Show older comments
Hello. I'm very new to MatLab so this is most likely a terribly easy question, but I just can't seem to figure it out. I run the same function on several sets of data, and what I would like for it to do is to store certain values into a matrix, let's say "hello", that stays in the workspace so that each set of data will add those values to "hello". Then at the end of analyzing all of the sets of data separately, I can then do an additional analysis on just those values that were put into "hello". So I'm trying to write the code to first check to see if hello is there, and if it isn't, to create it and enter in the values. If it is there, I'd just like to check to see if the values its going to add are already there, and if not, to add them to the end of the matrix. Sounds simple, below is what I have: function(x,y)
if exist('hello','var') == 0
assignin('base','hello',[x;y]);
elseif ismember(x,hello) == 1
disp Already contained
else
hello(end+1,:) = [x;y];
end
So it will create the variable if it's not there, but it just inputs "x" and "y" into the first row and overwrites whatever is there, every time. I'm sure there's a simple solution but I'm too new to have it be obvious to me. Any help would be very appreciated, thanks! -Jesse
Accepted Answer
More Answers (0)
Categories
Find more on Whos 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!