Luke Howard
Luke Howard

Reputation: 1

How to show the quantities of a column depending on the maximum or minimum values within another column in Scilab?

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

  1. 73.2823 65.7819 65.4822 71.8548 66.9929
  2. 64.1609 72.4888 70.1794 73.6414 72.7559
  3. 67.697 77.4425 66.8623 80.5608 64.5008
  4. 68.6878 67.2676 72.677 63.2135 70.43
  5. 63.9342 65.7662 72.644 64.8869 59.9772
  6. 63.4028 68.7683 68.9815 75.1892 67.5346
  7. 74.6561 73.3151 59.7284 68.051 72.3102
  8. 70.0562 65.729 70.6628 63.0937 68.395
  9. 66.7743 63.9934 77.9647 71.5777 76.1828
  10. 74.0286 69.4007 75.0921 77.7662 66.8436
  11. 71.1581 69.6735 62.098 73.5395 58.3739
  12. 65.0512 72.4265 69.6067 79.7869 63.8418
  13. 76.6979 67.0225 66.5917 72.5227 75.2782
  14. 71.4475 69.2517 64.8772 79.3226 69.4339
  15. 77.3946 67.8262 63.8282 68.3009 71.8961
  16. 75.6901 69.6033 71.444 64.3011 74.721
  17. 66.5793 77.6758 67.8535 68.9444 59.3979
  18. 63.5403 66.9676 70.279 75.9512 66.7766
  19. 69.6354 63.2632 68.1606 64.419 66.4785

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!

Current Code

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

Answers (2)

S. Gougeon
S. Gougeon

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

Attila
Attila

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

Related Questions