# fitting only continous line

1 view (last 30 days)
salman abbasi on 10 Nov 2020
Commented: salman abbasi on 10 Nov 2020
HI
I have a plot of coninouts lines(from top 1,3,6) and discontinous lines. I like to retrieve only the continous line. How can i achieve it using polyfit. Please note that slope of continous and discontinous line is same.
thanks

Show 1 older comment
salman abbasi on 10 Nov 2020
Hi Mathieu. The code is based on some work , which got me into this problem.
Also I posted another question, which was not answered, so it let me to re-arrange matrix, if this can be solved.
The original question :
Any other logic that retreives line 1,3,6 would work for me.
Please see the attach mat file
John D'Errico on 10 Nov 2020
Please don't ask the same question a third time. You've not gotten an answer to either question becuase it is not clear what you want. Vague questions tend not to get answers, or if they do get an answer, it will be slowly arriving, and probably not on-target.
You cannot use polyfit to fit a picture of a line. If you plotted the data, then pass the data for the line into polyfit. This is trivial. So your question seems not to be a problem of "fitting" a line, but of finding the data to fit.
You have said you want to fit only the continuous lines. But the fact is, any picture of a line as you have it is NOT continuous, but a discrete pixelated approximation to a line. And if you have plotted points, then again, it is a discrete set of points. So there is no such thing as a continuous line in any of what you have shown. If you can extract a specific set of points, then perhaps you may decide some measure that would disambiguate between points that are sufficiently close together to be effectively continuous. But that is a completely different question, totally unrelated to any question of fitting. This would become a pre-processing problem.
What you probably need to do is first, come up with a scheme that will extract the data you care about, and somehow decide which lines are ones you like and which are not. Only then does this become a problem about modeling. And it ertainly is not a question about MATLAB, not until you have some idea what you really need to do.
salman abbasi on 10 Nov 2020
@John. thant for the suggestion. I would be careful postinng same question more than once. I thought mayb by re defiining the problem, i could get the solution. Which i did. But no way i would like to disorganize the system. Thank you for your other suggestion. You are right, it was more of pre-processing problem and i learned from your response. Until next time. Have a good one!

David Goodmanson on 10 Nov 2020
Edited: David Goodmanson on 10 Nov 2020
Hi salman,
I have been off taking a look at this problem. The method below uses the fact that what you call the discontinouus lines have matrix entries close to zero in every other column. In the code below, small values are set to zero in the diagnostic matrix m, both so the spy option can be used and so the discontinuous lines can be removed. Figures 2 and 3 illustrate the difference. Figure 4 shows the indices where the first column of the diagnostic matrix is nonzero. That's where the blob representing the 'continuous' lines cross the axis in the original image plot. I will leave it to you to determine which index to use for each line. Note that the values in the diagnostic matrix m have nothing to do with m77. The matrix iis just used to find indices, and to use spy.
It's true that asking the same question more than once on the website is not a good approach. Better to amend the original answer to make it more clear what you are aking.
m = 1e6*m77; % rescale matrix for convenience
figure(1)
imagesc(m)
colorbar
% matrix has no exact zeros, so create some when m is small
tol = 1e-2;
m(abs(m)<tol)= 0;
figure(2)
spy(m)
axis square
% 'discontinuous' lines are zero in every other column, eliminate them
m = m(:,1:2:end).*m(:,2:2:end);
figure(3)
spy(m) % only the 'continuous' lines are left
axis square
firstcol = m(:,1);
figure(4)
plot(abs(firstcol))

#### 1 Comment

salman abbasi on 10 Nov 2020
@David. Thank you so much. It worked.Stuck to this problem for 3 days. This was my last step in producing result for my paper.Amazing.