MATLAB: “ans” variable function output unwanted

formulasudentfunctionMATLABoutputunwanted

Hi All,
I wrote a function in matlab in order to process some data. The function works fine and the results are as I want.
However, the function generates (unexpectatly) a variable "ans" which correspond to the first output of the function (time)
See my code below
I know that by default when a function is created all the first output value is returned. How can I avoid that (in order to leave clear the workspace)?
Thanks all for you help
G
%%Time Domain and Logging Frequency
time = Data_Raw(:,1)/1000; % 1st Colum is logging time in ms (from Arduino)
Fs = 1/mean(diff(time)); % Actual sample frequency (Hz)
TO_USER = ['The Real Logging Time of the system is in average ', num2str(Fs), ' Hz'];
clc
disp(TO_USER)
clear TO_USER
%%From Analog to Acceleration in g
ax = 3.5/(1023/2) * Data_Raw(:,2) - 3.5; % Accelerometer range -3.5g +3.5g


ay = 3.5/(1023/2) * Data_Raw(:,3) - 3.5; % Accelerometer range -3.5g +3.5g
az = 3.5/(1023/2) * Data_Raw(:,4) - 3.5; % Accelerometer range -3.5g +3.5g
%%Smooting the Accelerations
Ax = feval(fit(time, ax, 'smoothingspline'), time); % with parameter set to Auto
Ay = feval(fit(time, ay, 'smoothingspline'), time);
Az = feval(fit(time, az, 'smoothingspline'), time);
clear ax ay az;
%%HIGH PASS FILTER to compensate for the iniail position of the accelerometer (not always in level)
% filter definition
%Fc = 0.2; % cutoff frequency (Hz)
%[B,A]=butter(5,Fc/(Fs/2),'high'); % calcultate the filter numerator and denominator coeffients
%Ax_0 = filtfilt(B,A,Ax); % apply the filter defined in the lines above
%Ay_0 = filtfilt(B,A,Ay);
%Az_0 = filtfilt(B,A,Az);
%clear A; clear B; clear Fc; clear Fs;
% THE HIGH PASS FILTER MODIFY THE DATA TOO MUCH - THIS METHOD DOES NOT
% SEEMS APPROPRIATE, then the solution is zeroing taking the average off
%%Zeroing by taking off the average
Ax_zeroed = Ax - mean(Ax);
Ay_zeroed = Ay - mean(Ay);
Az_zeroed = Az - mean(Az);
%%Plotting
% Create figure
figure1 = figure;
% Create axes


axes1 = axes('Parent',figure1,'XTickLabel',{'','','','','',''},'Position',[0.11843187660668 0.682981090100111 0.774884318766067 0.309749136467419]);
box(axes1,'on');
hold(axes1,'all');
% Create plot


plot(time,Ax_zeroed,'Parent',axes1,'DisplayName','Longitudinal g');
% Create axes
axes2 = axes('Parent',figure1,'XTickLabel',{'','','','','',''},'Position',[0.118431876606679 0.364756889268502 0.774884318766067 0.309749136467419]);
box(axes2,'on');
hold(axes2,'all');
% Create plot
plot(time,Ay_zeroed,'Parent',axes2,'Color',[0 0.5 0],'DisplayName','Lateral g');
% Create ylabel
ylabel('Acceleration (g)','FontSize',16);
% Create axes
axes3 = axes('Parent',figure1,'XTick',[0 50 100 150 200 250],'Position',[0.118431876606679 0.0452654481856993 0.774884318766067 0.309749136467419]);
box(axes3,'on');
hold(axes3,'all');
% Create plot
plot(time,Az_zeroed,'Parent',axes3,'Color',[1 0 0],'DisplayName','Vertical g');
% Create xlabel
xlabel('Time (sec)','FontSize',14);
% Create legend


legend(axes1,'show');
% Create legend
legend(axes2,'show');
% Create legend
legend(axes3,'show');
%%Saving
% TO BE COMPLETED
end

Best Answer

Found the problem and it is very stupid (and embarassing)
The function is absolutely fine. I called the function with the command
[time,Ax,Ay,Az] = data_acq(varname)
but as any other function in Matlab, if I do not use the ";" like
[time,Ax,Ay,Az] = data_acq(varname);
Matlab automatically provides the first output of the function.
SOrry for populating this form with this stupid questions
Related Question