How to plot multiple columns with different variables
1 回表示 (過去 30 日間)
古いコメントを表示

I am trying to demonstrate the calibration of a pressure gauge, i have the values for the gauge at different offsets, and to prove it's calibrated i need to show the R^2 value using linear regression.I don't know how to plot this, i have attached an image as an example.
Each column represents a different offset, so for example the first column is at 0mm, second one 50mm etc. All values in column one were recorded at 0mm and so on.
2 件のコメント
Star Strider
2017 年 2 月 26 日
‘i have attached an image as an example.’
Not yet.
It would be helpful if you could also upload your data, preferably as a .mat file, so we can simply load it an not have to write specific code to import it.
I’m not clear on what your data are, for example multiple measurements at each point or a series of single observations over a range at each offset.
Also, please explain in a bit more detail your calibration procedure. It would help to interpret yoru data.
採用された回答
Star Strider
2017 年 2 月 26 日
I apologise for the delay. Life intrudes.
The regression is straightforward. It involves creating a long vector from the ‘Probe4’ array, matching it with an appropriate vector for ‘Y’, and then doing a simple linear regression. The ‘DesignMtx’ has as its first column ‘Probe4’ reshaped to a column vector, and the second a column vector of ones to calculate the intercept. The two coefficients are calculated in Prms. The rest of the code is straightforward.
The Code —
c = load('Dan Banbury Probe4Calibration.mat');
Probe_4 = table2array(c.Probe4);
DesignMtx = [Probe_4(:) ones(numel(Probe_4),1)];
Y = 0 : 50 : 200;
Yr = repmat(Y, size(Probe_4,1), 1); % Create Vector For ‘Y’
Yr = Yr(:); % Create Vector For ‘Y’
Prms = DesignMtx\Yr(:); % Estimate Parameters (Linear Fit)
xplot = Probe_4(1,:); % Create Vector For ‘X’
Ypred = [xplot' ones(size(Y(:)))]*Prms; % Calculate Regression Line
figure(1)
plot(xplot, Y, '.') % Plot Data
hold on
plot(xplot, Ypred, '-') % Plot Regression Line
hold off
grid
axis([0 ceil(max(xplot)) 0 max(Y)])
xlabel('V')
ylabel('Surface Elevation')
regtxt = sprintf('Surf Elev = %6.1f\\cdotV %+6.1f', Prms);
text(0.25, 150, regtxt)
The Plot —

Your data are tightly clustered, so only show up as large blue dots in this plot.
4 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!