what I write to a file is different to what I read back from the same file
Show older comments
I calculate calibration constants using a simple program as shown below for two variables. The input data is coded into a table.
% Set up calibration of EXP from Table
close all;
clear all
format SHORTE
clc
ExpNumber=input('Enter Experiment Number = ')
CAL_Path='c:\UNSW\RESEARCH_ACTIVE\BP_Research\BP_UP_DOWN_INVASIVE_NEW\Data_CAL\';
CAL_File=[CAL_Path 'CAL_EXP_' num2str(ExpNumber) '.mat']
%==========================================================================
% Enter Calibration Data into matrix below
Pressure=[0 44.2 91 139.2 186 242.4]
Count_cp=[168 12002 24002 36005 48008 62008];
Count_iabp=[2206 12124 22825 33549 44318 57075];
Calibration=table(Pressure, Count_cp, Count_iabp)
disp(ExpNumber)
disp([Calibration.Pressure' Calibration.Count_cp' Calibration.Count_iabp'])
%==========================================================================
% First for CP
x=Calibration.Count_cp';
y=Calibration.Pressure';
[f,q] = fit(x,y,'poly1')
figure(10)
plot(f,x,y)
% Now for IABP
X=Calibration.Count_iabp';
[F,Q]=fit(X,y,'poly1')
figure(20)
plot(F,X,y)
cp_cal=[f.p1 f.p2];
iabp_cal=[F.p1 F.p2];
save(CAL_File, 'ExpNumber','Calibration','cp_cal','f','q','iabp_cal','F','Q')
clear ExpNumber Calibration cp_cal f q iabp_cal F Q % Should not be necessary as I clear all variable on start of program
disp('Ended normally ***********')
This produces a file CAL_EXP_10, as the ExpNumber entered is 10
I then wrote a simple program to check the data written by reading it back, using the simple program, ReadCalFile.m
% Read CAL file
clear all
clc
Exp=input('Enter Experiment Number = ') % Required calibration data to read
CAL_Path='c:\UNSW\RESEARCH_ACTIVE\BP_Research\BP_UP_DOWN_INVASIVE_NEW\Data_CAL\';
CAL_File=[CAL_Path 'CAL_EXP_' num2str(Exp) '.mat']
load CAL_File
who
disp(Exp)
disp(ExpNumber)
disp([Calibration.Pressure' Calibration.Count_cp' Calibration.Count_iabp'])
%---------------------------------------------------------------------------------------------------------end of read program
The data read back when Exp is selcted as 10 returns data fro CAL_EXP_12.mat as shown below,
Enter Experiment Number = 10
Exp =
10 % Number of requested cal file to read
CAL_File =
'c:\UNSW\RESEARCH_ACTIVE\BP_Research\BP_UP_DOWN_INVASIVE_NEW\Data_CAL\CAL_EXP_10.mat'
Your variables are:
CAL_File Calibration ExpNumber Q f q
CAL_Path Exp F cp_cal iabp_cal
10 % Correct file requested
12 % Incorrect ExpNumber returned
0 1.6700e+02 6.2500e+02 % Data matrix returned does not match data for EXP_10
4.3200e+01 1.2006e+04 1.0620e+04
9.1700e+01 2.4010e+04 2.1303e+04
1.4000e+02 3.6015e+04 3.2152e+04
1.8710e+02 4.8009e+04 4.3059e+04
2.4160e+02 6.2001e+04 5.5854e+04
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!