Variable definition

3 views (last 30 days)
Hide
Hide on 28 Jul 2011
It is assumed there are 20000 values in a row.(as csv file)
I use "load" command, I can define new variable include all data. But I want to define variables that using partially data.
For example, data from No.1 to No.100 as variable "val_1", and data from No.101 to 200 as variable "val_2", .....and data from No.19901 to No.20000 as "val_200".
Can you tell me how to write the MATLAB code? Thank you.
  1 Comment
Hide
Hide on 28 Jul 2011
Thank you very much for your exact answer.
I can solve one of my problem.
When new problem is occur, I hope your teaching.
And I'm sorry for my bad English skills.
Thank you very much.

Sign in to comment.

Accepted Answer

Rick Rosson
Rick Rosson on 28 Jul 2011
  1. Instead of having 200 separate variables, it might be easier to create a single variable containing the 20,000 values arranged as a 2D matrix, consisting of 100 rows x 200 columns (or vice versa). This arrangement of your data will make it much easier to analyze and visualize the data in MATLAB, which is inherently based on vectors and matrices.
  2. Also, you may want to consider using the csvread function instead of the load function to read the data in from your CSV file.
Please try the following:
filename = 'myfile.csv';
X = csvread(filename);
Y = reshape(X,100,200);
Now you can access any one of the 200 columns of data as follows:
k = 40; % select a particular column k
V = Y(:,k); % all rows for the k-th column
HTH.
Best, Rick
  1 Comment
Hide
Hide on 28 Jul 2011
Thank you very much for your exact answer.
I can solve one of my problem.
When new problem is occur, I hope your teaching.
And I'm sorry for my bad English skills.
Thank you very much.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!