1
date         time        machine     power    energy    heat
?            ?           ?           MW       kJ        kJ
2/15/2016    20:50:46    kuka        45       22        22
2/15/2016    20:50:47    kuka        50       24        22
2/15/2016    20:50:48    kuka        56       26        22
2/15/2016    20:50:49    kuka        58       28        22
2/15/2016    20:50:50    kuka        62       30        22
2/15/2016    20:50:51    kuka        60       32        22
2/15/2016    20:50:52    kuka        64       34        20

I have a textfile and I imported data using importdata() command in matlab

I have tried Delimiter with space ' ' and '\t'

All data is saved in a struct as fine I as need but the problem is in the first line all of it is saved in one cell like date time machine power energy heat

All of the other data like ? , MW , KJ and 45 are save in separate cells which are fine.

I want data from the first row as separate entities like data time machine etc

If I save that cell in a variable name X then output is like 'date time machine power energy heat'

When I check class of this its char

What I want know is to convert this char to a string so that I can continue writing code for my GUI

4
  • 3
    String == Character array in MATLAB, (but you also have cell arrays of strings). Commented Feb 16, 2016 at 14:33
  • You can probably design a class names string and use that one, but I would not recommend it to anyone who actually want his code to work well (someone may have done it since he thought it prettier , but this person have likely paid the price in blood). Matlab have a lot of functions which deals with "cell arrays of strings". And writing a custom string clase would not only be slow, but also force you to rewrite all functions handling strings as char arrays (and also "cell array of strings"). Commented Feb 16, 2016 at 15:36
  • Cell Array are much better for handling Strings and it is more memory efficient than multiple Char Arrays. Commented Feb 16, 2016 at 15:47
  • What should I do to save date time and machine etc to store in separate variables Commented Feb 16, 2016 at 16:16

1 Answer 1

1

Answering after your comment

d = X{1}

Take any variable like Z use textscan to get your desired result

Z = textscan(d , '%s');

This will make Z a cell of order (1 X 1)
Z{1}(1) will be date
Z{1}(2) will be time
Z{1}(3) will be machine
......

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.