Effacer les filtres
Effacer les filtres

How to extract data efficiently from table or 2D array?

12 vues (au cours des 30 derniers jours)
Purnjay Peshawaria
Purnjay Peshawaria le 23 Juin 2020
Commenté : Adam Danz le 23 Juin 2020
I imported data from excel into MATLAB. I want to use MATLAB's curve fiiting toolbox to explore relationship between different variables. Is there a more efficient way to extract data rather than doing it for each column? Please note I want to access all columns separately. Excel spreadsheet attached.
T = importdata('SelfStorageData.xlsx');
T1 = T.data.ExampleLeases;
T2 = T.data.TypicalMoveIn;
T3 = T.data.TypicalMoveOut;
unit = T1(:,1);
type_indicator = T1(:,3) ;
width = T1(:,4);
length = T1(:,5);
days_available = T1(:,6);
days_occupied = T1(:,7);
time_occupied = T1(:,8);
average_stay = T1(:,9);
first_occupancy = T1(:,10);
average_lease = T1(:,11);
occ = T1(:,12);
standard_rate = T1(:,13);
lease_rate = T1(:,14);
effective_rate = T1(:,15);
last_standard_rate_change = T1(:,16);
last_lease_rate_change = T1(:,17);
Also, If I read table, and want to use curve fitting toolbox, how can I extract data from each column of the table in a more efficient manner?
T1 = readtable('SelfStorageData.xlsx', 'Sheet', 'Example Leases');
T2 = readtable('SelfStorageData.xlsx', 'Sheet', 'Typical Move In');
T3 = readtable('SelfStorageData.xlsx', 'Sheet', 'Typical Move out');
T1.Properties.VariableNames = {'unit' 'typeCharacter' 'typeIndicator'...
'width' 'length' 'daysAvailable' 'daysOccupied' 'timesOccupied' 'averageStay'...
'firstOccupancy' 'averageLease' 'Occ.' 'standardRate' 'leaseRate' 'effectiveRate'...
'lastStandardRateChange' 'lastLeaseRateChange'};
type_indictor = T1.typeIndicator;
width = T1.width;
length = T1.length;
days_available = T1.daysAvailable;
days_occupied = T1.daysOccupied;
time_occupied = T1.timesOccupied;

Réponses (1)

Adam Danz
Adam Danz le 23 Juin 2020
Extracting data from a matrix/table into individual variables is the most inefficient way to use those values.
Data stored in a matrix/table is tidy, well organized, efficient, and compact. Use indexing instead. Indexing is one of the superpowers of Matlab. For example, instead of extracting column 9 to variable average_stay, just use data(:,9) as the input vector.
Here's some background on indexing with matrices
and with tables
  4 commentaires
Purnjay Peshawaria
Purnjay Peshawaria le 23 Juin 2020
I think I need to make my point clear. Lets say I want to explore the relationship between days_available i.e T1(:,6) and days_occupied i.e. T1(:,7) . If I don't do what I'm doing (extracting data from matrix into individual variables), how can I populate X data and Y data in the above figure? You are suggesting I can simply access 9th column as data(:,9). But I need to name it because I can't put this directly in X data.
Adam Danz
Adam Danz le 23 Juin 2020
In that case, it looks like you'll need to break apart the arrays/tables into separate variables and there's no shortcut to what you're already doing.
However, the curve fitting tool is good for explortation, to fine-tune your fitting proceedure. But in the end, you should use the fitting functions directly and for that, you can using indexing.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by