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)
Mostra commenti meno recenti
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
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...
Risposte (1)
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
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.
Vedere anche
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!