Hi,
I am new to importing data from text files to MATLAB for data processing. I have experience doing this process from excel to MATLAB, however this seems a bit more tedius.
I have a text file which I need to extract the 1st line of numeral text (line 11) as the Y coordinate matrix, the second line of numerical text (line 12) as the X coordinate matrix and lines 3-7 (lines 13-17) as the Z coordinate Matrix. This data will then be plotted on a contour plot (code already completed and found below). I also need to extract the 1st line of text (line 3) to insert as the figure's title (a below).
Code:
%plotting MSI yacht 1
figure
contourf(N_X1,N_Y1,N_Z1,50,'edgecolor','none')
title(a);
colormap cool %map colour style
xlabel('Peak Period (t)');
ylabel('Heading (deg)');
c = colorbar('southoutside');
c.Label.String = ('MSI%');

 Réponse acceptée

Adam Danz
Adam Danz le 5 Août 2019
textChar = fileread('example.txt');
textCell = strsplit(textChar,'\n')';
y = str2num(textCell{11});
x = str2num(textCell{12});
z = str2num([textCell{13:17}]);
titleStr = textCell{3};
titleStr = strrep(titleStr, 'Graph Title - ', ''); %Remove Graph Title -

Plus de réponses (0)

Catégories

En savoir plus sur Color and Styling dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by