add cell or struct as title matlab plot

3 次查看(过去 30 天)
Hi,
See my script below, I need to add the changing variable 'num' as title name. How can i fix that?
for i = 3:3
num = subFolders(i).name
num2 = struct2cell(num)
folder = ['C:\Users\dit\Documents\MATLAB\RawData\',num]; f = dir(fullfile(folder,'*.csv')); g = numel(f);
figure
title('How can I add num here?')
for k = 1:g
filename = fullfile(f(k).folder, f(k).name);
CSVData = readmatrix(filename, 'Range', 1, 'Delimiter', ','); [filepath,name,ext] = fileparts(filename); indexCSV = [(0:size(CSVData,1)-1)' CSVData];
xC{k,1}=CSVData(:,7); yC{k,1}=CSVData(:,8); zC{k,1}=CSVData(:,9); radC{k,1}=CSVData(:,2)/2;
indexC =indexCSV(:,1); [valCL, idxCL] = max(indexC);
plot3(xC{k,1},yC{k,1},zC{k,1},'-b')
hold on
end
folder = ['C:\Users\dit\Documents\MATLAB\Centerlines_Python\',num]; f = dir(fullfile(folder,'*.txt')); g = numel(f)-1;
for i = 0:g
Ofilename = fullfile(f(i+1).folder, f(i+1).name);
DataText=load(Ofilename);
x = DataText(:,1); y = DataText(:,2); z = DataText(:,3);
plot3(x,y,z,'-')
hold on
end
pause
close
end

采纳的回答

Star Strider
Star Strider 2021-2-11
Since ‘num’ should be a simple character vector (at least it is when I tested this in R2020b), one of these should work:
title(num) % Includes Extension
title(extractBefore(num,'.')) % Removes Extension
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by