How to extract data efficiently from table or 2D array?
이전 댓글 표시
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;
답변 (1개)
Adam Danz
2020년 6월 23일
0 개 추천
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
Purnjay Peshawaria
2020년 6월 23일
Adam Danz
2020년 6월 23일
Look at the variables in the command window so you can see their size, shape, etc.
Judging from the code in your question, T1 is a matrix, days_occupied is a column vector. So that error message makes perfect sense.
Purnjay Peshawaria
2020년 6월 23일
Adam Danz
2020년 6월 23일
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.
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
