MATLAB Answers

0

For loop execution for saving data in a matrix or file

Asked by Darpan Verma on 13 Mar 2019
Latest activity Edited by madhan ravi
on 13 Mar 2019
Accepted Answer by KSSV
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

  0 Comments

Sign in to comment.

1 Answer

Answer by KSSV
on 13 Mar 2019
Edited by KSSV
on 13 Mar 2019
 Accepted Answer

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

  2 Comments

thanks KSSV. Ok ill take the course Thanks for the suggestion. i just started usung MATLAB.
@Darpan: You can do Matlab Onramp course which takes only few hours to complete.

Sign in to comment.