Effacer les filtres
Effacer les filtres

Meshgrid - RGB triplet plots

2 vues (au cours des 30 derniers jours)
dave epic
dave epic le 9 Sep 2015
Commenté : dave epic le 10 Sep 2015
I'm trying to plot data in polar coordinates mapped to RGB data.
Using a standard xy axis this is trivial, but I can't seem to plot a mesh grid with RGB triplets in the same way. Below is a working example. Figure 1 displays the data in a Cartesian grid (theta vs. rho), with the color axis represented by RGB triplets.
Figure 2 displays the meshgrid following the polar to Cartesian grid transformation - but I have only plotted the intensity of the red (R) value.
Please could somebody advise on the line of script that will allow me to plot the semi-circle shown (Figure 2) with RGB values, not intensity as in the example.
Thanks in advance.
%
clear all; close all;
theta = linspace(0,pi,18);
rho = linspace(0,pi/2,9);
C(:,:,1) = rand(numel(theta),numel(rho));C(:,1,1) = 0.5;
C(:,:,2) = rand(numel(theta),numel(rho));C(:,1,2) = 0.5;
C(:,:,3) = rand(numel(theta),numel(rho));C(:,1,3) = 0.5;
figure(1)
imagesc(theta,rho,C)
xlabel('theta');ylabel('rho');
[TH,R] = meshgrid(theta,rho);
[X,Y] = pol2cart(TH,R);
figure(2)
surf(X,Y,C(:,:,1)') % this is only the values of the R triplet
xlim([-pi/2 pi/2]);ylim([-pi/2 pi/2]);
axis square
view(0, 90)

Réponse acceptée

arich82
arich82 le 9 Sep 2015
I'm not entirely sure how your actual data is formatted, but your dummy data for C needs to transpose the theta and rho dimensions to agree with meshgrid's output.
Also, to specify C as an RGP triplet to surf, I think you must explicitly pass the Z argument.
See if the below can be adapted to your needs:
clear;
rng(1);
theta = linspace(0,pi,18);
rho = linspace(0,pi/2,9);
z = 0; % define z explicitly
C = rand(numel(rho), numel(theta), 3); % transpose oringinal rho and theta dims
%
figure(1)
imagesc(theta,rho,C)
xlabel('theta');ylabel('rho');
%
[TH,R,Z] = meshgrid(theta,rho,z);
[X,Y] = pol2cart(TH,R);
figure(2)
surf(X,Y,Z,C) % specify Z explicity to use C as RGB triplet
xlim([-pi/2 pi/2]);ylim([-pi/2 pi/2]);
axis square
view(0, 90)
  2 commentaires
Walter Roberson
Walter Roberson le 9 Sep 2015
Or a little more compactly,
surf(X,Y,zeros(size(X)),'CData',permute(C,[2 1 3]))
view([0 90])
axis equal
dave epic
dave epic le 10 Sep 2015
Both of these are great solutions. Thanks.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by