Info

此问题已关闭。 请重新打开它进行编辑或回答。

How can I get a vector from a structure ? Having trouble pulling out out the vector of structure.

1 次查看(过去 30 天)
% using the excel data
[FileName, PathName] = uigetfile('*.xlsx','Select Excel files to analyze:','MultiSelect','off');
[status, sheets] = xlsfinfo([PathName, FileName]);
summary_data = xlsread([PathName, FileName],sheets{1});
Volume = summary_data(:,1); % in mL
Time = summary_data(:,2); % in Seconds
Power = summary_data(:,3); % in watts;
%numsheets = length(sheets);
data = struct('volume',[],'time',[],'power',[]);
for j = 1:length(sheets)-1 ;
rawdata = xlsread([PathName, FileName],sheets{j+1});
data(j).volume = rawdata(:,1);
data(j).time = rawdata(:,2);
data(j).power= rawdata(:,3);
end
% analyze the std, and mean
for j = 1: length(sheets)-1;
data(j).flowRate = (data(j).Volume/data(j).Time);
data(j).meanQ = mean(data(j).flowRate);
data(j).stdQ = std(data(j).flowRate);
end
%% pulling vector from structure
mean_flowRate = [data.meanQ];
std_flowRate = [data.stdQ];
% first graphsubplot(1,2,1);hold on, box on, axis squarefor
for j = 1:length(sheets)-1;
plot(data(j).Time,data(j).Volume,'o','MarkerEdgeColor','k','MarkerFaceColor',clrlist{j});
end
xlabel('Time [s]');
ylabel('Volume [mL]');
%% This is the error I keep getting !
Reference to non-existent field 'meanQ'.
Error in Lab1 (line 25)
mean_flowRate = [data.meanQ];

回答(1 个)

Walter Roberson
Walter Roberson 2019-4-4
length(sheets) is 1, so length(sheets)-1 is 0, so your for j loops are not being executed, so no fields exist in the structure other than the ones you initialized to, volume, time, and power.

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by