How to plot multiple columns with different variables

1 回表示 (過去 30 日間)
Dan Banbury
Dan Banbury 2017 年 2 月 26 日
コメント済み: Star Strider 2017 年 2 月 27 日
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
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.
Dan Banbury
Dan Banbury 2017 年 2 月 26 日
編集済み: Dan Banbury 2017 年 2 月 26 日
Apologies, the picture has now been uploaded along with the .mat file. We did an experiment in a coastal lab and used wave gauge's to measure the surface elevation. In order to be confident in the results we first needed to calibrate the resistive wave gauges. There were 6 in total. I wanted to analyse one first then i can repeat the process for the other 5. The picture shows the data recorded for Probe 4 at the various offsets. The data for each offset is recorded over a period of time. I should be able to get a plot similar to the image i have included in this post. Any help would be really appreciated.

サインインしてコメントする。

採用された回答

Star Strider
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 件のコメント
Dan Banbury
Dan Banbury 2017 年 2 月 27 日
Thank you very much! Really appreciate the help.
Star Strider
Star Strider 2017 年 2 月 27 日
As always, my pleasure.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by