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 日

0 投票

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 日
編集済み: Ilan Boulet 2022 年 6 月 28 日
Hello,
Thank you for your answer, but the problem is not the y-axis limit. I would like to swap every X and Y axis for each column of Z axis.
Star Strider
Star Strider 2022 年 6 月 28 日
I do not have the data, and it is difficult to understand what your code does, and to understand what you want to do.
However, assuming that all the surf arguments are equal-sized matrices, simply change the order of the arguments to get the result you want.
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 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by