MATLAB Answers

Organize data in matrix

13 ビュー (過去 30 日間)
shima kasaei
shima kasaei 2019 年 8 月 14 日
コメント済み: Neuropragmatist 2019 年 8 月 14 日
I have .xlsx file with data of the points of a specific domain, data are not organized but each x,y has its own data which is called wz in my file, all of the z coordinates are the same as the data is for a plane of a same z.
I want to organize data in a matrix whose rows represent of y (ascending), and columns represent of x coordinate in ascending order, and the matrix fills with data (wz) for each specific x and y coordinate.
I want to do this in order to use 'pcolor' command to be abld to plot the color fill map.
Here is a part of my data:
wz Points:0 Points:1 Points:2
-24 5.6 0.01 0.05
-95 5.6 7.50E-10 0.05
-24 5.6 0.01 0.05
-1.40E+02 5.6 0 0.05
-95 5.6 0 0.05
-1.40E+02 5.6 7.50E-10 0.05
-0.88 5.6 0.02 0.05
-24 5.6 0.01 0.05
-0.93 5.6 0.02 0.05
-0.06 5.6 0.03 0.05
-0.063 5.6 0.03 0.05
-0.0034 5.6 0.04 0.05
-0.063 5.6 0.03 0.05
-0.00051 5.6 0.04 0.05
0.0023 5.6 0.05 0.05
-0.00032 5.6 0.05 0.05
-0.0037 5.6 0.06 0.05
-0.0014 5.6 0.06 0.05
0.0008 5.6 0.07 0.05
-0.00083 5.6 0.07 0.05
-0.00051 5.6 0.08 0.05
0.00056 5.6 0.08 0.05
0.0012 5.6 0.09 0.05
I would appreciate any help.

  1 件のコメント

dpb 2019 年 8 月 14 日
So what is each column of the above???


回答 (1 件)

Neuropragmatist 2019 年 8 月 14 日
If I understand correctly you have an excel file with 4 columns. One column contains x values, one y values, one z values (which are all the same) and another column contains some data values. You want to load the data and plot it all as an image with the data values at each x,y position?
This is certainly doable but it would be easier with the full dataset, maybe you could provide the xlsx file?
In the meantime, you can use xlsread or readtable to get the data into matlab:
Are the x,y coordinates actually row,column indices? If so you can use sub2ind to convert them to linear indices if you know the original size of the image:
However, in the small snippet you give above it looks like they are decimal numbers, which would mean the data are actually scattered x,y points? If so you would need to use scatteredInterpolant to generate the image you want:
Lastly, I would recommend imagesc over pcolor:
Hope this helps,

  2 件のコメント

shima kasaei
shima kasaei 2019 年 8 月 14 日
Thank you so much for your reply, the .xlsx data is the same as you understand, the columns order is data (wz), x coordinat, y coordinate, and z coordinate.
And about scatter data, I have a plane of mesh (square mesh) and the coordinates are for the boundary points of each cell, however, I want to plot each x,y,z coordinate in a color which represents the value of data (wz).
I think I should not use interpolation as they are not related to each other.
Please correct me if I am wrong.
Neuropragmatist 2019 年 8 月 14 日
OK, maybe you could upload one of the files for us to look at?
Because there are so many potential problems with the x,y coordinates that it would be easier to just look at a whole set.


Community Treasure Hunt

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

Start Hunting!

Translated by