How to plot the results below ?

2 次查看(过去 30 天)
Hi,
Please see the code below I used to extract the information from the folder. So the folder has 28 sub-folder with the name "Run 12-27-56.Adaptive PIV.6uqqm6yu", and so on. I want to plot on X-axis number of floder like 1,2,,3,4,5,6....28 and on y-axis corresponding file name (only the number part for example 12-27-56) which is a timestamp actually. Can you help, I am posting the code and result below.
Code:
close all; clear all; clc
%Location of the directory
Location = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_Vector_Masked';
% Get a list of all files and folders in this folder.
files = dir(Location);
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir];
% Extract only those that are directories.
subFolders = files(dirFlags); % A structure with extra info.
% Get only the folder names into a cell array.
subFolderNames = {subFolders(3:end).name} % Start at 3 to skip . and ..
%Print folder names to command window.
for k = 1 : length(subFolderNames)
fprintf('Sub folder #%d = %s\n', k, subFolderNames{k});
end
Results:
Sub folder #1 = Run 12-27-56.Adaptive PIV.6uqqm6yu
Sub folder #2 = Run 12-28-48.Adaptive PIV.6uqqlrqv
Sub folder #3 = Run 12-29-46.Adaptive PIV.6uqqlgku
Sub folder #4 = Run 12-30-23.Adaptive PIV.6uqql4fz
Sub folder #5 = Run 12-31-15.Adaptive PIV.6uqqkre7
Sub folder #6 = Run 12-31-50.Adaptive PIV.6uqqkfgv
Sub folder #7 = Run 12-32-25.Adaptive PIV.6uqqk3d3
Sub folder #8 = Run 12-33-17.Adaptive PIV.6uqqjqh2
Sub folder #9 = Run 12-33-54.Adaptive PIV.6uqqjctq
Sub folder #10 = Run 12-34-27.Adaptive PIV.6uqqiyst
Sub folder #11 = Run 12-35-04.Adaptive PIV.6uqqip1p
Sub folder #12 = Run 12-36-17.Adaptive PIV.6uqqidrr
Sub folder #13 = Run 12-36-47.Adaptive PIV.6uqqi25r
Sub folder #14 = Run 12-37-21.Adaptive PIV.6uqqhnwu
Sub folder #15 = Run 12-37-58.Adaptive PIV.6uqqhcsl
Sub folder #16 = Run 12-38-37.Adaptive PIV.6uqqh0on
Sub folder #17 = Run 12-39-27.Adaptive PIV.6uqqgp8m
Sub folder #18 = Run 12-40-01.Adaptive PIV.6uqqgdqt
Sub folder #19 = Run 12-40-36.Adaptive PIV.6uqqg1kn
Sub folder #20 = Run 12-41-11.Adaptive PIV.6uqqfpie
Sub folder #21 = Run 12-42-03.Adaptive PIV.6uqqfco7
Sub folder #22 = Run 12-43-07.Adaptive PIV.6uqqf0sv
Sub folder #23 = Run 12-43-59.Adaptive PIV.6uqqenyl
Sub folder #24 = Run 12-44-36.Adaptive PIV.6uqqdwdb
Sub folder #25 = Run 12-45-16.Adaptive PIV.6uqqdkcu
Sub folder #26 = Run 12-45-51.Adaptive PIV.6uqqd6wt

采纳的回答

Cris LaPierre
Cris LaPierre 2022-1-14
I would suggest converting the extracted timestamps to durations. Then you can just plot it. The x value will be the index number of the timestamp (1, 2, 3, ...) and the y value will be the time, formatted as a time.
It takes a little manipulation to get things formatted correctly, but not a lot of code.
subFolderNames(1) = "Run 12-27-56.Adaptive PIV.6uqqm6yu";
subFolderNames(2) = "Run 12-28-48.Adaptive PIV.6uqqlrqv";
subFolderNames(3) = "Run 12-29-46.Adaptive PIV.6uqqlgku";
subFolderNames(4) = "Run 12-30-23.Adaptive PIV.6uqql4fz";
subFolderNames(5) = "Run 12-31-15.Adaptive PIV.6uqqkre7";
subFolderNames(6) = "Run 12-31-50.Adaptive PIV.6uqqkfgv";
subFolderNames(7) = "Run 12-32-25.Adaptive PIV.6uqqk3d3";
subFolderNames(8) = "Run 12-33-17.Adaptive PIV.6uqqjqh2";
subFolderNames(9) = "Run 12-33-54.Adaptive PIV.6uqqjctq";
subFolderNames(10) = "Run 12-34-27.Adaptive PIV.6uqqiyst";
subFolderNames(11) = "Run 12-35-04.Adaptive PIV.6uqqip1p";
subFolderNames(12) = "Run 12-36-17.Adaptive PIV.6uqqidrr";
subFolderNames(13) = "Run 12-36-47.Adaptive PIV.6uqqi25r";
subFolderNames(14) = "Run 12-37-21.Adaptive PIV.6uqqhnwu";
subFolderNames(15) = "Run 12-37-58.Adaptive PIV.6uqqhcsl";
subFolderNames(16) = "Run 12-38-37.Adaptive PIV.6uqqh0on";
subFolderNames(17) = "Run 12-39-27.Adaptive PIV.6uqqgp8m";
subFolderNames(18) = "Run 12-40-01.Adaptive PIV.6uqqgdqt";
subFolderNames(19) = "Run 12-40-36.Adaptive PIV.6uqqg1kn";
subFolderNames(20) = "Run 12-41-11.Adaptive PIV.6uqqfpie";
subFolderNames(21) = "Run 12-42-03.Adaptive PIV.6uqqfco7";
subFolderNames(22) = "Run 12-43-07.Adaptive PIV.6uqqf0sv";
subFolderNames(23) = "Run 12-43-59.Adaptive PIV.6uqqenyl";
subFolderNames(24) = "Run 12-44-36.Adaptive PIV.6uqqdwdb";
subFolderNames(25) = "Run 12-45-16.Adaptive PIV.6uqqdkcu";
subFolderNames(26) = "Run 12-45-51.Adaptive PIV.6uqqd6wt";
dates = extractBetween(subFolderNames,"Run ",".");
dates = replace(dates,'-',':');
dates = duration(dates,"InputFormat","hh:mm:ss")
dates = 1×26 duration array
12:27:56 12:28:48 12:29:46 12:30:23 12:31:15 12:31:50 12:32:25 12:33:17 12:33:54 12:34:27 12:35:04 12:36:17 12:36:47 12:37:21 12:37:58 12:38:37 12:39:27 12:40:01 12:40:36 12:41:11 12:42:03 12:43:07 12:43:59 12:44:36 12:45:16 12:45:51
plot(dates)
  3 个评论
Cris LaPierre
Cris LaPierre 2022-1-14
I used the help documentaton for MATLAB. Go there and then just search for each of the functions I used.

请先登录,再进行评论。

更多回答(1 个)

Voss
Voss 2022-1-14
Here is something you can try:
close all; clear all; clc
%Location of the directory
Location = 'F:\3-PIV_Experimental_Data\Outlet_110\Data_LaserSheet_A\Data_Vector_Masked';
% Get a list of all files and folders in this folder.
files = dir(Location);
% Get a logical vector that tells which is a directory.
dirFlags = [files.isdir];
% Extract only those that are directories.
subFolders = files(dirFlags); % A structure with extra info.
% Get only the folder names into a cell array.
subFolderNames = {subFolders(3:end).name} % Start at 3 to skip . and ..
timeStamps = regexp(subFolderNames,'(\d+)-(\d+)-(\d+)','tokens');
timeStamps = vertcat(timeStamps{:});
timeStamps = cellfun(@str2double,vertcat(timeStamps{:}));
date_of_year = [2022 1 14];
y = datetime( ...
date_of_year(1),date_of_year(2),date_of_year(3), ...
timeStamps(:,1),timeStamps(:,2),timeStamps(:,3));
plot(1:numel(subFolderNames),y);
  2 个评论
muhammad choudhry
muhammad choudhry 2022-1-14
Hi, thanks alot for your help. can you direct me to the documents you use to get the result please!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by