Azzera filtri
Azzera filtri

Variable definition

1 visualizzazione (ultimi 30 giorni)
Hide
Hide il 28 Lug 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 Commento
Hide
Hide il 28 Lug 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.

Accedi per commentare.

Risposta accettata

Rick Rosson
Rick Rosson il 28 Lug 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 Commento
Hide
Hide il 28 Lug 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.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by