How can I make different plots of each row on Matlab and then grab the linear equation of each graph?

1 visualizzazione (ultimi 30 giorni)
clc;
clear;
[one] = readcell('isochronedata.xlsx','Sheet','Sheet10_');
bv = one(:,5);
mass = one(:,2);
BV = cell2mat(bv);
Mass = cell2mat(mass);
for Row = 1:1:size(BV,1)
BV_ = BV(Row,1);
plot(BV,Mass)
end
This is all I have so far, it doesnt work. Im honestly not sure how to make a running total so each row is graphed. Let alone how to make Matlab give me the linear equation from two points.
I dont know if I want Matlab to grab a pair of points consecutively (first row and second row graphed, third row and fourth row graphed, fifth row and sixth row graphed) or if I should make it graph consecutively with the last point (first row and second row graphed, second row and third row graphed, third and fourth graphed and so on).
After that, I would like Matlab to tell me the linear equation of the graph for each one.
  5 Commenti
Lorena Sanabria
Lorena Sanabria il 22 Ott 2020
Hi!
I understand what she was asking now😅
and yes you are right, those are my columns of interest.
The two points I would grab to make a linear graph would be a pair of points consecutively, first row and second row graphed, second row and third row graphed, third and fourth graphed and so on.
I attached a picture of my excel sheet so it is easier to understand. I made a graph of the first two points i want. I would like matlab to graph it like that and to give me the linear equation of each graph.
dpb
dpb il 23 Ott 2020
It's always much easier for folks to help if attach data itself instead of pictures...can't do anything with them but look so to write code have to make up data besides when none provided...

Accedi per commentare.

Risposte (1)

dpb
dpb il 23 Ott 2020
data=readmatrix('isochronedata.xlsx','Sheet','Sheet10_');
bv = data(:,5);
mass = data(:,2);
for i=2:2:numel(bv) % rows in groups of two at a time...
x=bv(i-1:i); % convenient shorthand temporary variables
y=mass(i-1:i);
plot(x,y)
if i==2, hold on, end % set hold for subsequent plotting on same axes
cf=fit(x,y,'poly1') % fit each pair in succession
end
Depending on what is wanted, save the fit objects cf in cell array or do whatever is wanted with the result inside the loop before going on to the next. See the Fit Postprocessing doc for fit to see about properties and methods.
  2 Commenti
Lorena Sanabria
Lorena Sanabria il 26 Ott 2020
Hi again!
Thank you so much, that definitely got me somewhere. However I got an error and I spent some time trying to figure out what it means but I've had no luck. Attached is the error message it shows me.
Also, I noticed that you advised me to save the fit objects "cf" in a cell array before going on to the next. I assume you mean I should save the graph, but how do I make the code go on to the next one?
dpb
dpb il 26 Ott 2020
Modificato: dpb il 26 Ott 2020
Just copy and paste the text of the message from the command window, not images...much easier to read and way less real estate! :)
Apparently you don't have either Curve Fitting or Statistics Toolboxes so don't have the higher-level fit function to use. Bummer!
polyfit is in base product but it returns just the coefficients without all the other niceties...see the documentation for it and its mate polyval
I've got meeting in town now, gotta' run...will look in again later.

Accedi per commentare.

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by