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%');

 채택된 답변

Adam Danz
Adam Danz 2019년 8월 5일

0 개 추천

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 -

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

질문:

2019년 8월 5일

댓글:

2019년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by