Reference to a variable

조회 수: 13 (최근 30일)
Gil Levi
Gil Levi 2011년 5월 4일
hi, I am loading a huge amount of data into a database. The database is dynamic and sometimes will hold 50 separate entities and sometime less. Each entity than has a list of up to 10,000 separate variables, each of which is a table of values. I need a way to hold pointers (or references) to the variables to ease later scanning of the database of only particular data. I don't know in advance the number of items in each entity or the number of entities. I was thinking using whos and/or fieldnames to scan the database and get a complete list of all the variable names. But once I have the reference (for example as a string of the var name) how to I access that variable's value? For example if there is a variable called David and its value is 7, and if I have a string 'David', how can I get the value from the string?

채택된 답변

Jan
Jan 2011년 5월 4일
What exactly is "a database"? Do you mean a database?
The last sentence of your question sounds like you want to use dynamic fieldnames:
Data.Field1 = rand(3)
Name = 'Field1';
Index = {2, 3}
disp(Data.(Name)(Index{:}))
But the initial part of the question let me assume, that you better use a database program.
  댓글 수: 1
Gil Levi
Gil Levi 2011년 5월 4일
I would use a database but the computations are extremely complex and can't be done in a practical manner without MATLAB (or similar). So I prefer implementing it in MATLAB. When I mentioned database I was thinking about a variable that will hold all the data. When I load such a variable later and I want to access only specific fields within the data and be able to scan only through these fields (i.e. run a for loop only on the specific data that I need) and I have a string name of the field which is a small part of the entire variable. ........... running your example I think you answered my question. I can use fieldnames to learn all available fields in the variable (my database) and then use the strings with "your" parenthesis method to access them later. Thanks a lot.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by