Color-coding a 2D plot

5 次查看(过去 30 天)
Joana Silva
Joana Silva 2018-7-18
Hi everyone! I want to make a nice colour graph with my data but I don't know exactly what I'm looking for. So in my experiment, I measured the excess pore pressure in 12 different positions in a deposit of sand (40x40cm side view). I have an example of the results I have for the transducers 9, 10, 11 and 12 (Fig.1). What I want is an easy way to visualise this changes in pressure in all transducers at once through time. For example, a square 40x40cm and the changes in colour (pressure) for each transducer area for the first 2 minutes (Fig.2). I know the exact position of each transducer: 12cm between them and 2cm from the top/bottom. Basically I want 2min "video" to see which part of the sand deposit is contracting or dilating during the experiment. I'm new in MatLab. I only know the basic codes to analyse my data. But now I have other ideas to present this data. Can you help me please? Thanks! Joana
  4 个评论
jonas
jonas 2018-7-18
Upload the data, not the code. Also, don't upload code as images...

请先登录,再进行评论。

采纳的回答

jonas
jonas 2018-7-18
编辑:jonas 2018-7-18
The simplest way to create an animation is to first create a plot and then update the 'XData', 'YData' and 'ZData' properties (or in this case just the 'ZData'). You can spend days adjusting the visuals. This code provides the basics for plotting values over time in a 4x3 grid. I hope this is somewhat what you had in mind. Happy to help further if it's not.
Note: You did not give me the variable S, so I could not adjust the data accordingly. I just used the data you gave me.
DenseSand = fileread('D.Test.lvm');
Densesant = strrep(DenseSand,',','.');
DenseSand = str2num(DenseSand);
%%Data
Num_Samples2 = [1:1:size(DenseSand,1)]';
MeasFr = 200;
Time2 = Num_Samples2 / MeasFr;
T=DenseSand.*0.1;
z=T(:,[4 5 9 2 6 10 3 7 11 4 8 12]);
%%Coordinates
x=repmat(2:12:26,1,4);
y=repmat(2:12:38,3,1);
y=y(:);x=x(:);
%%Create finer mesh
[Xq,Yq]=meshgrid(0:1:40,0:1:40);
%%Plot
h=surf(Xq,Yq,zeros(size(Xq)));
set(gca,'ZLim',[0 1e5])
colormap('jet')
view(2)
%%Interpolate and plot each frame
for i=1:length(Time2)
h.ZData=griddata(x,y,z(i,:)',Xq,Yq,'nearest');
drawnow
title(['Time: ',num2str(Time2(i))])
end
This code takes more than 2 minutes to run on my machine. It's easy to increase the time between animations by inserting a pause, however the minimum time can only be changed by making the code more efficient. You can however increase the amount of frames by not plotting every value, simply change the iterations to
i:step:length(Time2)
  2 个评论
jonas
jonas 2018-7-19
' what variable S? '
In your image you subtract some mean of a variable S from T. But the code does not show what S is.
Joana Silva
Joana Silva 2018-7-19
编辑:Joana Silva 2018-7-19
Ah, yes. Well the variable S it doesn't matter. It is just to subtract the additional pressure from the deposition of the sand in the flume to make sure that all transducers start measuring from zero.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by