matlab code for a function that stores input in memory and gives 1 if it is not already present in memory and 0 if it is already present in memory

1 view (last 30 days)
I want to design matlab code for a function that stores input in memory and gives 1 if it is not already present in memory and 0 if it is already present in memory. Forexample
if i wwrite compareinput('X'); (for first time it should give 1 & for all other iterations for same input it should give 0)
so far I tried this code but didnt worked out.
function [ Y ] = compareinput( X )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
lastposition=0;
if lastposition~=X
Y=1;
else
Y=0;
end
lastposition=X;
end

Answers (1)

Walter Roberson
Walter Roberson on 22 Dec 2015

Categories

Find more on Structures 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!