surfc function : plot goes wrong

1 次查看(过去 30 天)
Hello there,
I am trying to plot my datas with the 'surfc' function, and after struggling and tinking some vectors to give them the good size, I can run my code without any error, but the plots aren't what I excepted (see the photos linked to this post).
This is the code:
ColumnToKeep=7;
d=dir(fullfile('C:\Users\boulet\Documents\Recherche\2022\,'*.txt')); % use appropriate wild card name
fnameNew=fullfile('C:\Users\boulet\Documents\Recherche\2022\,'OutputNameOfChoice.txt');
nFiles=numel(d);
for i=1:nFiles
data=readmatrix(fullfile(d(i).folder,d(i).name));
if i==1, OutData=zeros(size(data,1),nFiles);end
OutData(:,i)=data(:,ColumnToKeep); %Sauvegarder dans la n-ième colonne
end
writematrix(OutData,fnameNew)
%This first part works extremely well, it creates the 'OutData'file, which
%is a 162x71 double
%%
dataup=OutData(1:81,:);
datadown=OutData(81:161,:);
Vgup=linspace(-40,40,1);
Vgup2=transpose(Vgup);
Vgup3=repmat(Vgup2,81,71);
Vgdown=linspace(40,-40,1);
Vgdown2=transpose(Vgdown);
Vgdown3=repmat(Vgdown2,81,71);
time=0:1:80;
time2=transpose(time);
time3=repelem(time2,1,71);
figure
surfc(time3,Vgup3,dataup);
title('Sweep up','FontSize',20),view([0 0 1]),xlabel('Time (s)','FontSize',20),ylabel('Vg (V)','FontSize',20)
set(gca,'FontSize',16)
shading flat
colorbar('FontSize',16)
figure
surfc(time3,Vgdown3,datadown);
set(gca,'FontSize',16)
shading flat
title('Sweep down','FontSize',20),view([0 0 1]),xlabel('Time (s)','FontSize',20),ylabel('Vg (V)','FontSize',20)
colorbar('FontSize',16)
I can't tell what is wrong ..
If some of you have any advise, I'd be grateful.

采纳的回答

Star Strider
Star Strider 2022-6-28
It would help to have representative data to experiment with.
In its absence, try this —
ylim([39.9 40.1])
Experiment with that approach, for example something like this:
q = 0.1;
ylim(40+[-1 1]*q)
Change (decrease) the value of ‘q’ until you get the desired result.
.
  4 个评论
Ilan Boulet
Ilan Boulet 2022-6-28
I am sorry I wasn't clear. I linked the data to this post.
On this data text, there are several columns, each correspond to one measurement. For each of those measurement, I would to associate the whole vector time and the whole vector Vg, it means plot the first column of data in function of time and Vg, then do the same for the second one etc.
I tried to change the order the argument, it changes nothing.
I hope I have been more understandable.
Thank you
Star Strider
Star Strider 2022-6-28
The various ‘Vg’ vectors do not make sense to me. The ‘Vgup’ variable is a scalar equal to 40 and the ‘Vgdown’ variable is a scalar equal to -40.
I am doing my best to make sense of this. (The ‘OutData’ variable is a (162x71) matrix, and ‘dataup’ here is a (81x71) matrix.)
See if this does what you want —
OutData = readmatrix('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1048790/OutputNameOfChoice.txt');
dataup = OutData(1:81,:);
datadown = OutData(82:end,:);
Vgup=linspace(-40,40,36);
Vgdown=linspace(40,-40,35);
time=0:80;
figure
surf(time, Vgup, dataup(:,1:36).')
xlabel('Time')
ylabel('Vg_{up}')
zlabel('Z')
.

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by