I have one function code in which initially pressure values recorded in voltage and converted into pressure values by using formula. I want to store these calculated values.
1 view (last 30 days)
Show older comments
function getdata_2021_07_28(src,event,datapoints_event,datapoints_liveplot,ai,data,Fs)
% s.ScansAvailableFcn = @(src,event) dataCapture(src, event, capture, hGui);
% dataCapture(src, ~, c, hGui)
% s.ScansAvailableFcn = @(src,event) getdata2(src,event,datapoints_event,datapoints_liveplot,data);
% getdata2(src,~,datapoints_event,datapoints_liveplot,data)
global olddata
global data
[eventData, eventTimestamps] = read(src, src.ScansAvailableFcnCount, ...
'OutputFormat', 'Matrix');
newdata(:,1) = eventTimestamps; % timestamps
newdata(:,2:length(ai)+1) = eventData;
% Add the time stamp and the data values to data. To write data sequentially,
data=[data; newdata];
if length(olddata)<datapoints_liveplot
olddata=[olddata; newdata];
else
olddata=[olddata(datapoints_event+1:end,:) ; newdata];
end
% plot(olddata(:,1) ,olddata(:,2:length(ai)+1))
% for i=1:length(ai)
% leg{i} = ['ai' num2str(ai(i)) '=' num2str(mean(newdata(:,i+1))) ' V'];
% end
% legend(leg,'FontSize',14,'Location','NorthOutside','Orientation','Vertical');
Time(:,1)=olddata(:,1);
P1=olddata(:,2);
% (0.2-1.3) 0.9720 , 3.01791
% P1=1.0186+(0.275*P1)-(0.275*3.9777);
P1=0.2+(0.275*P1)-(0.275*1);
P2=olddata(:,3);
% (0.1-1.3) 1.1399, 4.481224
% P2=1.1635+(0.3*P2)-(0.3*4.5462);
P2=0.1+(0.3*P2)-(0.3*1);
P3=olddata(:,4);
%(0.1-2) 1.0558, 3.81739
% P3=1.0798+(0.475*P3)-(0.475*3.0622);
P3=2+(0.475*P3)-(0.475*5);
P4=olddata(:,5);
%(0-150)
P4=(31.25*P4)-(31.25);
PMTX(:,1)=Time(:,1);
PMTX(:,2)=P1;
PMTX(:,3)=P2;
PMTX(:,4)=P3;
PMTX(:,5)=P4;
% figure;hold on
% pp1=plot(Time(:,1),P1(:,1)); M1="P_tank";
% pp2=Plot(Time(:,1),P2(:,1)); M2="P_Discharge";
% pp3=Plot(Time(:,1),P3(:,1)); M3="P_Suction";
%
% % legend([pp1,pp2,pp3], [M1, M2,M3]);
% % hold off
% % plot(Time(:,1),[P1(:,1) P2(:,1) P3(:,1)])
% hold on
% yyaxis left
% ylabel('Pressure')
hold on
plot(Time(:,1),P1(:,1),Time(:,1),P2(:,1),Time(:,1),P3(:,1),Time(:,1),P4(:,1))
% plot(Time(:,1),P1(:,1),Time(:,1),P2(:,1),Time(:,1),P3(:,1))
% plot(Time(:,1),P1(:,1));
% plot(Time(:,1),P1(:,2));
% plot(Time(:,1),P1(:,3));
% yyaxis right
% load count.dat;
% ylable('Flow')
% plot(Time(:,1),P4(:,1))
% hold of
% % leg{i} = ['ai' num2str(ai(i)) '=' num2str(mean(newdata(:,i+1))) ' P'];
%drawnow
legend('Tank Pressure','Suction Pressure','Discharge Pessure','Flow');
xlabel('time [s]')
ylabel('Pressure')
xlim([ min(olddata(:,1)) max(olddata(:,1)) ] )
end
0 Comments
Answers (1)
Sreeram
on 9 Jun 2025
Hi Avinash,
I am assuming that the question is about how to save the calculated pressure values to the PC during or after data acquisition.
For permanent storage, the data in PMTX (or any other variable) can be saved to disk using MATLAB’s "save" function for MAT files or "writematrix" to export as CSV. This can be done once acquisition is complete or periodically inside the callback, depending on the specific needs.
Refer to the documentations for more details and examples.
0 Comments
See Also
Categories
Find more on Data Acquisition Toolbox Supported Hardware 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!