MATLABR2024a上での最大値を求めるコード

% Open the text file in read mode
fileID = fopen('yourfile.txt', 'r');

% Read the file content line by line
data = textscan(fileID, '%s', 'Delimiter', '\n');
lines = data{1};

% Close the file
fclose(fileID);

% Convert the required lines to numbers
startLine = 1450;
endLine = 1500;
relevantLines = str2double(lines(startLine:endLine));

% Find the maximum value
maxValue = max(relevantLines);

% Display the maximum value
disp(['The maximum value between lines ', num2str(startLine), ' and ', num2str(endLine), ' is: ', num2str(maxValue)]);
The maximum value between lines 1450 and 1500 is: -Infinity
% テキストファイルを読み込み、そのファイルの1450行目から1500行目までの中の最大値を表示する
fileID = fopen('001_Power Spectrum_8kHz_16384_CH1_Graph1.txt', 'r');

% ファイルの内容を行ごとに読み込む
data = textscan(fileID, '%s', 'Delimiter', '\n');
lines = data{1};

% ファイルを閉じる
fclose(fileID);

% 必要な行を取得し、2列目の数値に変換する
startLine = 1450;
endLine = 1500;
relevantLines = str2double(extractBetween(lines(startLine:endLine), ',', ','));

% 最大値を見つける
maxValue = max(relevantLines);

% 最大値を表示する
disp(['1450行目から1500行目までの2列目の最大値は: ', num2str(maxValue)]);