Reputation: 1
My problem is related to unfamiliarness with the program as a whole. An attempt has been made to display the values of time at the maximum and minimum values, but I'm not sure how to approach the problem. I have successfully displayed the maximum and minimum values, but I have not been able to link values from another column to those quantities.
The problem reads: "a. Read the data file (using the fscanfMat('SENSOR.txt') command) and print the number of sensors and the number of seconds of data contained in the file. Remember, column 1 does not contain sensor data; it contains time data. ( Hint: Use the size function.) b. Find both the maximum value and the minimum value recorded on each sensor. Determine at what times they occurred. c. Find the mean and standard deviation for each sensor and all the data values collected."
The SENSOR.txt is: 0. 70.6432 68.347 72.3469 67.6751 73.1764
Part (b) the area I am having issues with is writing code that both finds the maximum and minimum values within each column (I have completed), but then to also include the time values (column 1) at which each of those values occur. These values are then meant to be put into an matrix and displayed.
An example of my current code is below and I would greatly appreciate some assistance. Thanks!
I tried two different methods. The first being to display each column as its own variable, but this seemed ridiculous and overly complicated. I then tired to establish a [big,place(2:6)]=max(:,(2:6)) to identify the location of each maximum(or minimum) value and take that value as a variable and then display based off of the variable I defined previously. I expected this to work, but I run into the issue of "Submatrix Incorrectly Defined".
Upvotes: 0
Views: 39
Reputation: 911
Here is a working proposal:
Data = fscanfMat('SENSOR.txt');
data = Data(:, 2:$);
[M ,kM] = max(data, 'r');
kM = Data(kM,1)';
[m, km] = min(data, 'r');
km = Data(km, 1)';
average = mean(data, 'r');
spread = stdev(data, 'r');
[M ; kM ; m ; km ; average ; spread]
yielding
--> [M ; kM ; m ; km ; average ; spread]
ans =
77.3946 77.6758 77.9647 80.5608 76.1828
15. 17. 9. 3. 9.
63.4028 63.2632 59.7284 63.0937 58.3739
6. 19. 7. 8. 11.
69.72589 69.10054 68.86801 71.22993 68.264865
4.5471074 3.9223221 4.4091651 5.7190233 5.2411597
Upvotes: 0
Reputation: 615
I recommend you too look at the find
function in the Scilab help, which gives you the "true" indices (of a vector or matrix), therefore in a vector V
the index of the maxium value (or values if the same max value is repeated!) is:
i = find( V == max( V ) );
The corresponding time in vector T
is then t=T(i)
. Of course you can use submatrix indices of the full original data matrix:
i = find( M(:,2) == max( M(:,2) ) );
t = M(i,1);
(If you find the answer useful, please do not forget to accept it, so others will see that your problem is solved.)
Upvotes: 0