How can I make different plots of each row on Matlab and then grab the linear equation of each graph?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
dpb
am 23 Okt. 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...
Antworten (1)
dpb
am 23 Okt. 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 Kommentare
dpb
am 26 Okt. 2020
Bearbeitet: dpb
am 26 Okt. 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.
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!