# How do I create a 3D plot that can show both magnitude of air speed and temperature of the air?

2 views (last 30 days)
Noah Roberts on 8 Jul 2021
Commented: Noah Roberts on 8 Jul 2021
I have a 3-Axis machine that takes a discrete number of evenly-spaced data points in a 3D volume. An Arduino takes in the wind speed and temperature values at each (x, y, z) point and prints them to the serial monitor for MatLab to read. I would like to visualize both on the same 3D plot, preferably with colored arrows or cones (length of arrow is speed, color is temp), but I'm not quite sure how. Here's what I have so far to take in the speed and temperature values and plot only the wind speed data in a quiver plot. There are 125 total points in the 3D space, with the serial monitor releasing two values per data point.
a = instrfind();
fclose(a);
s = serial('COM4','BaudRate',9600);
fopen(s);
speeds=[];
temps=[];
for i=1:250 %125 total 3d points, two values each
if(mod(i,2)==0) %every other value is either temp or wind speed
m=str2double(fscanf(s));
temps=[temps,m];
else
n=str2double(fscanf(s));
speeds=[speeds,n];
end
speeds=speeds.';
temps=temps.';
%All of this code below arranges the data in a 3D grid the way it is gathered
wind_speed = reshape(speeds,[5 5 5]);
temperature = reshape(temps,[5 5 5]);
for i=1:1:5
wind_speed(:,:,i)=wind_speed(:,:,i).';
wind_speed(:,:,i)=fliplr(wind_speed(:,:,i));
temperature(:,:,i)=temperature(:,:,i).';
temperature(:,:,i)=fliplr(temperature(:,:,i));
for j=1:1:5
if(mod(j,2)==0)
wind_speed(j,:,i)=fliplr(wind_speed(j,:,i));
temperature(j,:,i)=fliplr(temperature(j,:,i));
else
wind_speed(j,:,i)=wind_speed(j,:,i);
temperature(j,:,i)=temperature(j,:,i);
end
end
end
wind_speed
temperature
%Plotting the data
[x, y, z] = meshgrid(1:1:5);
u = x-x; % x-component of vector field
v = y-y; % y-component of vector field
w = wind_speed(:,:,:); % z-component of vector field
[cx, cy, cz] = meshgrid([0 1 2 3 4]);
quiver3(x,y,z,u,v,w);
% set(h, 'FaceColor', 'none', 'EdgeColor', 'g');
camlight; lighting gouraud;
grid on; box on;
axis([0 6 0 6 0 6]);
view(-30, 30);

VBBV on 8 Jul 2021
%if true
w = wind_speed(:,:,:)
T = temperature(:,:,:);
quiver3(x,y,z,u,v,w)
hold on
quiver3(x,y,z,u,v,T)
Noah Roberts on 8 Jul 2021
Thank you for your response. This does work to plot two different quiver plots on the same graph, but I was curious if it was possible to plot the temperature and speed on a single arrow with its magnitude being speed and color being temperature.

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by