add cell or struct as title matlab plot

3 vues (au cours des 30 derniers jours)
Dion Theunissen
Dion Theunissen le 11 Fév 2021
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

Réponse acceptée

Star Strider
Star Strider le 11 Fév 2021
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
.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by