MATLAB HELP--URGENT
Hi, I am trying to find a function or code which will do the following:
Search an array for a specific violation I have coded. When the violation is found it is printed to an Excel sheet along with the time and value just before and just after the violation.
The problem I am having is that sometimes there is no data value (only a time) either right before or right after the violation. The way I have my code is that it just prints the value before and after using i-1/i+1 in a loop (i being the row in the data where the violation occurred). This is resulting in an empty cell in my printed Excel sheet if there happens to be no data. How can I create a loop so that it searches for the cell just before and just after the violations that CONTAINS data.
Search an array for a specific violation I have coded. When the violation is found it is printed to an Excel sheet along with the time and value just before and just after the violation.
The problem I am having is that sometimes there is no data value (only a time) either right before or right after the violation. The way I have my code is that it just prints the value before and after using i-1/i+1 in a loop (i being the row in the data where the violation occurred). This is resulting in an empty cell in my printed Excel sheet if there happens to be no data. How can I create a loop so that it searches for the cell just before and just after the violations that CONTAINS data.
0
Comments
k=1;
for j = 1:6
if Checks(j)
for i = 1:length(A.data(j).value.d(:))
if A.data(j).value.d(i) >= Values(1,j);
Results{j}{k,1} = sectogmt(A.data(j).value.t(i));
Results{j}{k,2} = A.data(j).value.d(i);
if i>1
* if isempty(i-1)
* i=i-1;
else
Results{j}{k,3} = sectogmt(A.data(j).value.t(i-1));
Results{j}{k,4} = A.data(j).value.d(i-1);
end
end
if i<length(A.data(j).value.d(:))
* if isempty(i+1)
* i=i+1;
else
Results{j}{k,5} = sectogmt(A.data(j).value.t(i+1));
Results{j}{k,6} = A.data(j).value.d(i+1);
end
end
elseif A.data(j).value.d(i) <= Values(2,j)
Results{j}{k,1} = sectogmt(A.data(j).value.t(i));
Results{j}{k,2} = A.data(j).value.d(i);
if i>1
* if isempty(i-1)
* i=i-1;
else
Results{j}{k,3} = sectogmt(A.data(j).value.t(i-1));
Results{j}{k,4} = A.data(j).value.d(i-1);
end
end
if i<length(A.data(j).value.d(:))
* if isempty(i+1)
* i=i+1;
else
Results{j}{k,5} = sectogmt(A.data(j).value.t(i+1));
Results{j}{k,6} = A.data(j).value.d(i+1);
end
end
end
k=k+1;
end
end
end
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:15</td> <td>SYS_LOSS</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:16</td> <td>
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:17</td> <td>
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:18</td> <td x:num="" align="right">235.82</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:19</td> <td>
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:20</td> <td>
</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:21</td> <td x:num="" align="right">67.15</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:22</td> <td>
</td> </tr> </tbody></table>
So, for example 235.82 is the violation. The spreadsheet needs to print out the time and violation, which I have no problem. The number just before and just after the violation, along with the time also need to be printed to the spreadsheet. The empty cells as well as the SYS_LOSS is creating problems in my code. What I want the final printed spreadsheet to look like is:
<table x:str="" style="border-collapse: collapse; width: 225pt;" width="299" border="0" cellpadding="0" cellspacing="0"><col style="width: 136pt;" width="181"> <col style="width: 89pt;" width="118"> <tbody><tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt; width: 136pt;" width="181" height="17">2009_010:10:01:13</td> <td style="width: 89pt;" x:num="" width="118" align="right">67.14</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:18</td> <td x:num="" align="right">235.82</td> </tr> <tr style="height: 12.75pt;" height="17"> <td style="height: 12.75pt;" height="17">2009_010:10:01:21</td> <td x:num="" align="right">67.15</td> </tr> </tbody></table>
1) When you say isempty(i-1), you're just testing if i-1 is empty, not whatever is indexed by i-1.
2) Same when you say if i. You're just testing i, not whatever is at i.
out will be a cell array of the data.
<length(a.data(j).value.d(></length(a.data(j).value.d(></length(a.data(j).value.d(>
What's wrong with the code i gave you?
Requires string or character array input.
Error in ==> KUtemps>LimitCheck at 762
if(str2num(A.data(j).value.d(ii)))
Error in ==> KUtemps>Plot_Callback at 685
LimitCheck(handles);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> KUtemps at 49
gui_mainfcn(gui_State, varargin{:});
??? Error while evaluating uicontrol Callback
for ii = 1:length(A.data(j).value.t(:))