这是实现您想要的代码和结果图:
clear; clc;
%% Initialize variables.
filename = 'C:\Users\UserName\FileLocation\data.txt';
delimiter = {'((',' ',')'};
%% Read columns of data as strings:
% For more information, see the TEXTSCAN documentation.
formatSpec = '%q%q%[^\n\r]';
%% Open the text file.
fileID = fopen(filename,'r');
%% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'ReturnOnError', false);
%% Close the text file.
fclose(fileID);
data = repmat({''},length(dataArray{1}),2);
for col=1:length(dataArray)-1
data(1:length(dataArray{col}),col) = dataArray{col};
end
% Plotting each height value
PlotMatrix = [];
leg = {};
for k = 1:length(data(:,2))
if strcmp(data{k,1}(1:6),'height')
leg{end+1,1} = data{k,1};
if ~isempty(PlotMatrix)
figure(1)
hold on
plot(PlotMatrix(:,1), PlotMatrix(:,2))
hold off
end
PlotMatrix = [];
else
PlotMatrix = [PlotMatrix; [str2double(data{k,1}), str2double(data{k,2})]];
end
end
% Plot last matrix
if ~isempty(PlotMatrix)
figure(1)
hold on
plot(PlotMatrix(:,1), PlotMatrix(:,2))
hold off
end
legend(leg{:});