Matlab problem: stuck on printing out a measurement at a certain time please help

Discussion in 'Programmer's Corner' started by saruji, Apr 7, 2012.

  1. saruji

    Thread Starter New Member

    Oct 18, 2011
    so slightly stuck on a problem:I am given a data set, whos first column is time from 0-19 seconds with 1 second intervals, the columns 2:6 have various sensor measurements. I am asked to extract the min measurement and the max measurements for each sensor and then use MatLab to determine at what time they occurred... stuck on finding out at what time they occurred, any help would be greatly appreciated, thanks

    attached the sensor.dat file

    my code so far:

    or for quick reference of my code so far
    %Read the data file and print the number of sensors and the number of
    %seconds of data contained in the file. Before that load the sensor.dat
    [seconds, sensors] = size(sensor)

    %Problem 4.4b
    %Found both the maximum value and the minimum value recorded on each
    %sensor, and showed at what time they occured.
    max1 = max(sensor:), 2))
    max2 = max(sensor:), 3))
    max3 = max(sensor:), 4))
    max4 = max(sensor:), 5))
    max5 = max(sensor:), 6))

    min1 = min(sensor:), 2))
    min2 = min(sensor:), 3))
    min3 = min(sensor:), 4))
    min4 = min(sensor:), 5))
    min5 = min(sensor:), 6))

    time = sensor:), 1)
    sensor = sensor:), 2:6)

    ???? not sure on how to proceed
  2. panic mode

    AAC Fanatic!

    Oct 10, 2011
    for i=2:N
    if sensor(i,1)>max1
  3. saruji

    Thread Starter New Member

    Oct 18, 2011
    thank you, I solved it a different way.

    max1 = sortrows(sensor, -2);
    max1_value = max(sensor:), 2))
    time_at_max1 = max1(1, 1)

    I sort a sensor column in descending order and then print out the readings from the top columns for the needed column.