Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
juan Ortiz
juan Ortiz le 4 Avr 2019
Clôturé : MATLAB Answer Bot le 20 Août 2021
% 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];

Réponses (1)

Walter Roberson
Walter Roberson le 4 Avr 2019
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.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by