How to extract data efficiently from table or 2D array?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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;
0 comentarios
Respuestas (1)
Adam Danz
el 23 de Jun. de 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 comentarios
Adam Danz
el 23 de Jun. de 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.
Ver también
Categorías
Más información sobre Data Import from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!