For loop execution for saving data in a matrix or file

3 ビュー (過去 30 日間)
Darpan Verma
Darpan Verma 2019 年 3 月 13 日
コメント済み: messaoudi nada 2021 年 9 月 24 日
Hi Everyone I have wrote a MATLAB code which fits the data for one curve and give me the value of x intercept. (linear fitting for the linear portion of the curve)
I have many curves similar to this one for which I need to use the same fit code which I wrote for one curve. So I think of writing a for loop to the whole code which will change the values of the x and y. I want all this data fit information for all the curve to be saved in one matrix (like the value of i, number of points it fitted, slope). For an instance for the below case the matrix values would be i = 1, number of points fitted = 4, slope = 0.5504. For changing the values I have this code. I need your input on this code, which I have below. I have the for loop written after this image. Please have a look and give your valuable suggestions/comments.
Thanks
for i =1:1:40
y = ((data2LoadR{3}(i,2:end))) %for all the 40 curves
x = (data2LoadR{1}) %x axis is same for all curves
%%......All the lines of code which I have for curve fit and give same
%%values I got in the screenshot case
Xintercept[1,i] = -b/m %save Xintercept in different location each time the loops run
n[2,i] = numel(A) %Save the number of points fitted
i[3,i] = i %Save the number of values of data
end

採用された回答

KSSV
KSSV 2019 年 3 月 13 日
編集済み: KSSV 2019 年 3 月 13 日
Mr Darpan VErma:
I strongly suggest you to take basic tutorial in MATLAB, it is very easy and saves your time. YOu need not to ask very simple questions in the forum. You are bound to waste time and reputation asking simple questions in the forum.
points = zeros(40,1) ;
numbervalues = zeros(40,1) ;
for i =1:40
y = ((data2LoadR{3}(i,2:end))) %for all the 40 curves
x = (data2LoadR{1}) %x axis is same for all curves
%%......All the lines of code which I have for curve fit and give same
%%values I got in the screenshot case
Xintercept[1,i] = -b/m %save Xintercept in different location each time the loops run
points(i) = numel(A) % What is A ??
numbervalues(i) = i % You need not to save this, it is already i = 1:40
end
  3 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 13 日
編集済み: madhan ravi 2019 年 3 月 13 日
@Darpan: You can do Matlab Onramp course which takes only few hours to complete.
messaoudi nada
messaoudi nada 2021 年 9 月 24 日
hi @KSSV ,please can u help me !, im working about machine learning models , so after extracting features from images i have a 12 structure data ,i want to save the data in a reference matrix and test matrix ,i tried this loop but it didn't work it just save the features of the last image in structure ! i don't know what's wrong here ! hope u can give help to me !
thanks in advance
for i=1:12
for iref=1:10
for jref=1:40
F1=data1_rf.(['p',num2str(iref)]).(['image',num2str(jref)]).Features;
for itst=1:2
for jtst=1:40
F2 =data1_T.(['p',num2str(itst)]).(['image',num2str(jtst)]).Features;
end
end
end
end
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCurve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by