Store data into an Array or variable

16 ビュー (過去 30 日間)
Jovanie Josol
Jovanie Josol 2013 年 3 月 5 日
BELOW is a part of my codes. ARDUNIO - MATLAB.
PROBLEM: I want to store all values of P, Q and V in every update of the loop so that it would now be easy for me to print it to excel using xlswrite.
CAN SOMEONE HELP ME WITH THIS. Or any alternative to store the data for DATA ACQUISITION FOR MY STUDY. your answers are a great help.
while strcmp(start,'DISCONNECT')
RxText = fscanf(serConn);
RxText = strtrim(RxText);
disp(RxText);
pause(0.5)
%%%%%%%for data acquisition
handles.counter = handles.counter + 1;
[InRange,power,va,var,pf,volt,current,id]=strread(RxText,'%s%s%s%s%s%s%s%s','delimiter',',');
%%%MAIN POWER ANALYZER
if strcmp(id,'B') %DATA FOR MAIN PA
set(handles.LP4,'String',power);
set(handles.LQ4,'String',var);
set(handles.LV4,'String',volt);
%%%%CONVERT STRING TO DOUBLE %%%%%%
P4= str2double(power);
Q4 = str2double(var);
V4 = str2double(volt);
%%%%CONDITION SET TO LOAD MAIN STAT
if P4>70 && P4<80
set(handles.STAT4,'String','WARNING');
elseif P4>80
set(handles.STAT4,'string','SYSTEM OVERLOAD');
else
set(handles.STAT4,'string','NORMAL');
end
%%%%%DATA ACQUISITION %%%%%
P4(handles.counter,1) = P4
%Q4(handles.counter,2) = Q4;
%V4(handles.counter,3) = V4;
% data = [P1 Q1 V1]
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 3 月 5 日
count = 0; %before loop
Inside the loop,
count = count + 1;
data(count, :) = [P1 Q1 V1];
  2 件のコメント
Jovanie Josol
Jovanie Josol 2013 年 3 月 5 日
Thanks for this. I will try and comment again what is the result.
Jovanie Josol
Jovanie Josol 2013 年 3 月 5 日
I HAVE A PROBLEM ENCOUNTERED. the data that will be stored will have zero. 3 zeros. I used 4 Power analyzers and used multiplexing. so i think y the zeros exist. HOW CAN I OMIT THE ZEROS??
data =
0 0 0
7.2000 84.3000 212.9900
0 0 0
0 0 0
0 0 0
7.2000 84.3000 212.9100
0 0 0
0 0 0
0 0 0
7.2000 84.3000 212.8600
0 0 0
0 0 0
0 0 0
7.2000 84.8000 213.1800

サインインしてコメントする。

その他の回答 (1 件)

Jovanie Josol
Jovanie Josol 2013 年 3 月 5 日
Got it! I put the code data(count,:) = [P1 P2 P3 P4] outside the if end condition. then what
P1 = get(handles.LP1,'string');
P2 = get(handles.LP2,'string');
P3 = get(handles.LP3,'string');
P4 = get(handles.LP4,'string');
P1=str2double(P1);
P2=str2double(P2);
P3=str2double(P3);
P4=str2double(P4);
data(count,:) = [P1 P2 P3 P4]

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by