surfc function : plot goes wrong

2 views (last 30 days)
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.

Accepted Answer

Star Strider
Star Strider on 28 Jun 2022
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 Comments
Star Strider
Star Strider on 28 Jun 2022
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')
.

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!