surfc function : plot goes wrong

조회 수: 1 (최근 30일)
Ilan Boulet
Ilan Boulet 2022년 6월 28일
댓글: Star Strider 2022년 6월 28일
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