0

If I have a database like this:

field = {'Name','GPA,'Salary'};
data = {'Jim', 3.2, $1000}

How to get data GPA '3.2' from my database to be my variable, so I can use it? Table name is 'data'.

ekad
  • 14,436
  • 26
  • 44
  • 46
  • 1
    in your example its `data{1,2}, but ifeel there is more to it than just those 2 lines of code. can you post the rest, maybe we can get a solution that always works. – Finn Sep 14 '16 at 07:35

1 Answers1

0

If you can work with this variables this is a matlab data structure called cell. the problem is that you have things that matlab can read

The first expression has an unclosed string

field = {'Name','GPA,'Salary'};

so it should be:

field = {'Name','GPA','Salary'};

The problem with the second is the dollar symbol you should or remove it or work as a string

data = {'Jim', 3.2, 1000}

then accessing to cell is easy here is the documentation

field{2}

ans =

GPA

you can work with the numbers inside a cell, with positions you know that GPA is position 2:

>> data = {'Jim', 3.2, 1000}

data = 

    'Jim'    [3.2000]    [1000]

>> data{2} = data{2} + 0.8

data = 

    'Jim'    [4]    [1000]
anquegi
  • 11,125
  • 4
  • 51
  • 67
  • Thanks for quick reply sir , but if i want to equal GPA to another number ex : GPA + 0.8 , how to arithmatic it ? what code i need use ? – Alfi Nugraha Sep 14 '16 at 07:53
  • thanks alot for the answer. I have another problem when i want to show database to gui, could you help me to solve it please? Code is below – Alfi Nugraha Sep 14 '16 at 08:04
  • it should be better to create a new question – anquegi Sep 14 '16 at 08:05
  • http://stackoverflow.com/questions/39488338/reference-to-non-existent-field-error-when-showing-database-data-to-editbox-in-g – Alfi Nugraha Sep 14 '16 at 11:31