필터 지우기
필터 지우기

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