add cell or struct as title matlab plot

조회 수: 3 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 2월 11일
답변: Star Strider 2021년 2월 11일
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