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 CenterFile Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by