Creating a 3D plot! I have never done before

Hey Guys,
I have an cell-array
c -> 116x1 cell
and a Vector
d -> 116x1 double!
For example the data x = c{1,1}(:,1), y = c{1,1}(:,2) and z = d(1,1) belong together.
I tried things with a for-loop or simmiliar but all i get is errors and bullshit. I dont know if i have to work with meshgrid or which plot i exactly need. I hope you guys can help me with that problem.
I put an example Plot to show u what i need (it is just an example from the internet). And my plot is going to touch the "ground".
Thank you very much. Hope u guys can help me.

8 commentaires

KSSV
KSSV le 11 Mai 2018
Attach your data.....your data belongs to structured or unstructured?
Stephen23
Stephen23 le 11 Mai 2018
Y. J.'s "Answer" moved here:
Hey KSSV, thanks for your fast reply. The problem is I'm not allowed to upload them here. Here are three screenshots. I hope this is enough to help me.
Y. J.
Y. J. le 12 Mai 2018
Modifié(e) : Y. J. le 12 Mai 2018
I don´t want to bother you... . But no ideas?I´m trying many things but i don´t really know how to handle the data for such an 3D Plot. I think it is going to look more something like that (but without the circels/Dots on the top):
Stephen23
Stephen23 le 12 Mai 2018
Modifié(e) : Stephen23 le 12 Mai 2018
How to plot your data depends on your data, which you have not told us enough about. Is the data scattered or gridded? What sequence are the X and Y values stored in?
You will need to put all of the data into numeric matrices/vectors, before plotting them. Trying to plot using loops will not help.
If you have gridded data then you should read about surf. All you would need to do is rearrange your data into the three matrices that it requires.
Hmm I think i have to start from the beginning. I have an file which looks similar to the .txt I attached here (the original is much bigger). And I read the file with the following code:
clc;
clear all;
fmt = '%f %f';
fid=fopen('Beispiel_Datei.txt','r');
k = 1;
while (~feof(fid))
k = k+1;
c(k-1,1) = textscan(fid,fmt,'collectoutput',true,'HeaderLines',7);
end
fmt = '%f ';
d = [];
while (~feof(fid))
l = fgetl(fid);
eqpos = strfind(l, '=');
if ~isempty(eqpos)
d = cell2mat([d; textscan(l(eqpos+1:end),fmt)]);
end
end
fid=fclose(fid);
end
(Feel free to tell me if you have some better ideas for the code above, Im still in the learning process)
I hope i can answer your questions: Is the data scattered or gridded? It should be gridded. What sequence are the X and Y values stored in? If you see the txt-file then u can see that always the time comes before an block of data (1/3 t = 0.000 s). So while i read the data I cut the blocks each time there is a new time value. In the original file their is roundabout 116 time values and blocks. So the data for X and Y is stored in the cell-Array "c" (x = c{1,1}(:,1), y = c{1,1}(:,2)) and the time value in the vector d (z = d(1,1))
If you need more information please let me know.
What do you mean with rearrange into the matrices? Can you please show me that on my example?
Stephen23
Stephen23 le 13 Mai 2018
Modifié(e) : Stephen23 le 13 Mai 2018
@Y. J: it is not clear to me how that data could be plotted as you wish. In the example file the X and Y values are always the same for three time (Z) values, so following your description and question you are trying to plot these three Z values for the same X and Y values. But both of the plots you have shown appear to be of functions, i.e. any X,Y pair maps to exactly one Z value. Your data and explanation seem to be inconsistent with this. Do all blocks contain exactly the same X,Y pairs?
Please clarify how to interpret the repeating X,Y values.
PS: It might help if you gave a bit more data than just three Z values. That won't form a very meaningful demonstration.
Y. J.
Y. J. le 14 Mai 2018
@Stephen Cobeldick: Thanks for your fast reply. The file I uploaded is just an example how the file i read from is formatted and how the data is structured. It wasn´t meant to be a exact example. Like I told in the opening i can´t upload the original file/data. The file is created by an device while measurement. Z represents the time it starts at 0.000 s and ends at a certain time. each data block corresponds to an time. The two columns represents the frequency and the acceleration of an specific device.
Do all blocks contain exactly the same X,Y pairs? No it don´t. Like in the text before it contains completely different data. Each data block is captured within a specific time.
Stephen23
Stephen23 le 14 Mai 2018
Modifié(e) : Stephen23 le 14 Mai 2018
@Y. J.: it would be much easier if you provided a file that really represents the data better, including data values that follow how the real files are arranged (e.g. the different X,Y pairs).
"It wasn´t meant to be a exact example"
Please give us an exact example. Use fake values if you don't want to give the real ones.
"What do you mean with rearrange into the matrices?"
The surf help explains what size the input X and Y matrices/vectors must be, relative to the Z matrix. It also shows how to use meshgrid to create them, so you can easily try it yourself on a small example and see what they look like.
"Can you please show me that on my example?"
Sure, once you give data that can be used to create a plot with.

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 11 Mai 2018

Modifié(e) :

le 14 Mai 2018

Community Treasure Hunt

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

Start Hunting!

Translated by