Plot 10100X3 matrix as a pixel plot.

I have a dataset called matrix of size 10100X3. matrix(1) and matrix(2) are the x y coordinates respectively and the matrix(3) value determines the color of the pixel. This format is not working with the image() function. Any ideas on how I can make this work?
fileID1 = fopen('flipmatrix1.txt');
matrixx = fscanf(fileID1, '%f',[3,inf]);
matrixx = matrixx';
fclose(fileID1);
fileID2 = fopen('flipmatrix2.txt');
matrixy = fscanf(fileID2, '%f',[3,inf]);
matrixy = matrixy';
fclose(fileID2);
matrix = [matrixx; matrixy];
qA = matrix(:,1);
qB = matrix(:,2);
time = matrix(:,3);
image( qA, qB, time);
colorbar;

6 Commenti

Please be very specific by what you mean by "not working". Does your code fail to run? If so, give us the complete error message. Or maybe it gives an unexpected result? What did you expect, and what is different?
Ideally, upload your data (or a small, representative sample) so that we can directly test your code.
Make it easy for us to help you!
This is a representative sample of the data:
qA qB time
0.000 -4.000 30.000
0.000 -3.920 30.000
0.000 -3.840 30.000
0.000 -3.760 30.000
0.000 -3.680 30.000
0.000 -3.600 30.000
0.000 -3.520 30.000
0.000 -3.440 30.000
0.000 -3.360 30.000
0.000 -3.280 30.000
0.000 -3.200 30.000
0.000 -3.120 30.000
Also, the code runs but it does not plot a pixel for each data point as you can see in the image. It is obviously a problem with how the data is being passed in the function, but I am not sure how to solve it. To clarify, I want to plot a pixel at qA, qB location with a color that varies depending on the time value.
Thanks!
That does not seem representative to me. If qA is always zero, then I would expect a single line, and if time never changes, I would expect a single color.
So far, the plot seems to reflect that data, so it is not really possible to diagnose your issue, with the information you have given us.
The dataset is of 10100X3. Those are just the first couple points. The plot I am intending to get looks just like the one attached. My question is, how should I pass the data into the image function to produce such a plot.

You are missing my basic point. When I said you should upload representative data, I meant that you should post a sample that should give a result with similar characteristics to what you expect. With the data and the code you shared, I get a plot that looks like this ...

This is exactly the image that I would expect from such data. So, it is not illustrating the problem you are having. We still need more information to help you.

These are the two txt files that this code is using.

Accedi per commentare.

 Risposta accettata

imagesc(reshape(time, 101, 100));
After that you need to set your colormap() . Your current color values, stored in time, are scalar values in the range -4 to +30, rather than being RGB values, so to get black at the center and yellow outside you are going to need to use a colormap.

2 Commenti

Thanks a lot!!
If this problem is solved, please Accept the answer.
I used scatter() to verify that the points were close to being on a grid, and plot() to verify that the progression was regular rather than in random order; after that it was a matter of finding the right reshape() to use. There is a possibility that your points are not exactly on the grid: if that is important then you will need to either griddata() or use surface() or patch() with texture mapping.
Getting a good colormap appears to be the major challenge.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by