Search code examples
stringfilematrixscilab

Scilab convert cell from matrix to string


Hello, I am beginner in Scilab and I have for homework process the measured values, which are saved in csv file. This is example of the values in that file:

&quot;Project Name:,&lt;Empty&gt;&quot;<br />
&quot;Company Name:,&lt;Empty&gt;&quot;<br />
&quot;User Name:,&lt;Empty&gt;&quot;<br />
&quot;Job Title:,&lt;Empty&gt;&quot;<br />
&quot;Location:,&lt;Empty&gt;&quot;<br />
&quot;Remarks:,&lt;Empty&gt;&quot;<br />
&quot;Date_Time,Test ID,Value_A,Unit_A,Function_A,MeterID_A,BluetoothID_A,Remarks_A&quot;<br />
&quot;2021-03-11 16:59:54,TP0,1968.2,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot;<br />
&quot;2021-03-11 16:59:55,TP1,1967.6,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot;<br />
&quot;2021-03-11 16:59:56,TP2,1966.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 16:59:57,TP3,1966.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 16:59:58,TP4,1966,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 16:59:59,TP5,1964,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:00,TP6,1945.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:01,TP7,1895.1,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:02,TP8,1856.6,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:03,TP9,1824.7,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:04,TP10,1803,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:05,TP11,1788.7,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:06,TP12,1773.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:07,TP13,1759.8,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:08,TP14,1752.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:09,TP15,1744.3,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:10,TP16,1734.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:11,TP17,1727.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:12,TP18,1723.8,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:13,TP19,1718.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:14,TP20,1713.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:15,TP21,1710.3,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:16,TP22,1708.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &quot;2021-03-11 17:00:17,TP23,1706.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF,&quot; &nbsp;

I am trying to get only the value of resistances with these commands:

 dates = mgetl(&#39;NTC2k2.csv&#39;) 
[start, final, match] = regexp(dates(1:$,1)),&#39;/[1-9.]*,Ω/&#39;)

But my BIG problem is that when I try use this code it throw exeption that the function regexp cannot work with matrix dates(1:$,1), please I do not know how to proceed next. Please help me, thanks you very much!


Solution

  • I suppose that you had some problems when pasting you csv file. If the file has the following content, which I suppose to be the case since a CSV file is not supposed to include html entities:

    Project Name:,<Empty>
    Company Name:,<Empty>
    User Name:,<Empty>
    Job Title:,<Empty>
    Location:,<Empty>
    Remarks:,<Empty>
    Date_Time,Test ID,Value_A,Unit_A,Function_A,MeterID_A,BluetoothID_A,Remarks_A
    2021-03-11 16:59:54,TP0,1968.2,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 16:59:55,TP1,1967.6,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 16:59:56,TP2,1966.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 16:59:57,TP3,1966.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 16:59:58,TP4,1966,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 16:59:59,TP5,1964,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:00,TP6,1945.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:01,TP7,1895.1,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:02,TP8,1856.6,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:03,TP9,1824.7,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:04,TP10,1803,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:05,TP11,1788.7,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:06,TP12,1773.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:07,TP13,1759.8,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:08,TP14,1752.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:09,TP15,1744.3,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:10,TP16,1734.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:11,TP17,1727.9,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:12,TP18,1723.8,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:13,TP19,1718.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:14,TP20,1713.5,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:15,TP21,1710.3,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:16,TP22,1708.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    2021-03-11 17:00:17,TP23,1706.4,Ω,Res,U1252B-MY52430232,U1177A-238EBF
    

    then the Scilab code to get the resistance column is very simple (I suppose that your file is named so.csv)

    --> csvRead("so.csv",[],[],"double",[],[],[],7)(:,3)
    
    ans  =
    
       1968.2
       1967.6
       1966.9
       1966.5
       1966.
       1964.
       1945.5
       1895.1
       1856.6
       1824.7
       1803.
       1788.7
       1773.5
       1759.8
       1752.9
       1744.3
       1734.4
       1727.9
       1723.8
       1718.5
       1713.5
       1710.3
       1708.4
       1706.4
    

    the last parameter with value 7 indicates the number of lines in the header of the file and the recursive extraction (:,3) selects the third column.