How do I extract value from a Cell array to text file or CSV file?

I have a figure with some exact(detected) point. See the figure.
I want to find the X-Level value and Y-Level value of the detected points. I found the code on this website. It works also good. The code is given below:
ax = gca;
obj_with_xd = findobj(ax, '-property', 'XData');
obj_with_right_markers = findobj(obj_with_xd, 'Marker', 'v', '-or', 'Marker', 'o', '-or', 'Marker', 's');
the_xd_cell = get(obj_with_right_markers', 'XData');
if ~iscell(the_xd_cell); the_xd_cell = {the_xd_cell}; end
the_yd_cell = get(obj_with_right_markers, 'YData');
if ~iscell(the_yd_cell); the_yd_cell = {the_yd_cell}; end
From this code, I want to extract the the_xd_cell and the_yd_cell Cell Array value in a text file or CSV file in that way like such that, R1: X-level: 42, Y-level: 0.908 again R2: X-level: 137, Y-level: 0.854 and so on for all detected point of RQS (Q1, Q2...).. How can I do that?
I also attached 2 screenshots for your easiness. The the_xd_cell cell is given below:
Some value of the_xd_cell is given below:
Help to solve this problem.

5 commentaires

upload your file to test
@Ravi Which file?
madhan ravi
madhan ravi le 25 Oct 2018
Modifié(e) : madhan ravi le 25 Oct 2018
ok I mean the datas of the cell , upload the_xd_cell
@Akib how did you detect the starting and ending and peak of the pulses accurately? what algorithm did you use?

Connectez-vous pour commenter.

 Réponse acceptée

madhan ravi
madhan ravi le 25 Oct 2018
Modifié(e) : madhan ravi le 25 Oct 2018
EDITED
the_xd_cell=load('the_xd_cell.mat')
the_xd_cell1(1,:)=the_xd_cell.the_xd_cell{1}
the_xd_cell2(1,:)=the_xd_cell.the_xd_cell{2}
the_xd_cell3(1,:)=the_xd_cell.the_xd_cell{3}
dlmwrite('sample.txt',the_xd_cell1,'delimiter',' ')
dlmwrite('sample.txt',the_xd_cell2,'delimiter',' ','-append')
dlmwrite('sample.txt',the_xd_cell3,'delimiter',' ','-append')

15 commentaires

When I run your code, it shows me this error!
Error using dlmwrite (line 104)
The input cell array cannot be converted to a matrix.
Use the_xd_cell=mat2cell(the_xd_cell)
And then save
Error using mat2cell (line 45)
Not enough input arguments.
its cell2mat sorry my mistake
the_xd_cell=load('the_xd_cell.mat')
the_xd_cell=the_xd_cell.the_xd_cell{3}
dlmwrite('sample.txt',the_xd_cell,'delimiter',',')
the above should work
Extremely Sorry! It doesn't work
madhan ravi
madhan ravi le 25 Oct 2018
Modifié(e) : madhan ravi le 25 Oct 2018
See the edited answer
@Ravi. Thanks for your answer and patience. Your code converts the_xd_cell and taking help from your code I can convert the_yd_cell. But I want the output in another way what I describe in the questions. That's mean I want every detected point X and Y coordinates. I hope will help me :)
@Ravi. I also have done the concatenation of X and Y cell value. See the photo:
But actually I want in this way:
I'll give an example for your to understand:
x=1:10
Y=10:-1:1
x(Y==7) % what does this do it extracts value of x when Y is 7
x(Y==Y) %extracts all x coordinates with corresponding Y cooedinates
like wise you can apply it to your case
Though I am new in Matlab. But its ok. I use your code create a text file and convert this text file in CSV file. Thanks for your help.
@Ravi, Hello, if you take a look at the first figure the_xd_cell is 3 * 1 cell. So when I run first time (guess cell 1 contains the data of square type object) but when I run the second time (cell 1 contains circle type object data). That's mean cell number is changing for different object type when I run the program second or more time.
How can I do the cell number constant (Like that cell 1 is always for square type object and cell 2 is always circle type object)

Connectez-vous pour commenter.

Plus de réponses (1)

C{1} = rand(1,26) ;
C{2} = rand(1,25) ;
C{3} = rand(1,26) ;
A = cell2mat(C)' ;
save 'data.txt' A -ascii

2 commentaires

@KSSV After running your code, it generates a text file but my result is fully changed!
They ate not changed.....you load it back into MATLAB using load and see....it is a format display that's it. Else you can use fprintf to save by specifying the format.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by