How can I use the excel import functionality in Matlab to import a table but to have the individual pices of data in the table rows to not be imported as 1x1 tables as well?
    조회 수: 3 (최근 30일)
  
       이전 댓글 표시
    
When I import excel spreadsheets as tables it imports each piece of data as a 1x1 table which creates problems when I want to operate on those variables. For example, I cannot create new variables that are the squares and cubes of existing variables when each piece of data is a 1x1 table. What is the best way to handle this? Can I have the excel import function import the excel sheet as a table but have it cast each piece of data as a double?
댓글 수: 0
채택된 답변
  Peter Perkins
    
 2018년 4월 24일
        
      편집: Rena Berman
    
 2024년 7월 16일
  
      I imagine what's happening is this: you are importing a spreadsheet using readtable, and you get a table.
>> t = readtable('myfile.xlsx')
t =
  5×3 table
     Var1       Var2       Var3  
    _______    _______    _______
    0.81472    0.09754    0.15761
    0.90579     0.2785    0.97059
    0.12699    0.54688    0.95717
    0.91338    0.95751    0.48538
    0.63236    0.96489    0.80028
Then you select one element of that table:
>> t(1,1)
ans =
  table
     Var1  
    _______
    0.81472
And so you are thinking that the import has created a bunch of little 1x1 tables.
But that isn't it at all. The short answer is that you likely need to use some other form of subscripting, probably something like
>> t.Var1(1)
ans =
      0.81472
The longer answer is that you likely do not want to select one value at a time. Doing vectorized calculations is usually the better way. No way to tell without more context.
댓글 수: 0
추가 답변 (1개)
  Ameer Hamza
      
      
 2018년 4월 23일
        Although you can change the entries in a MATLAB table. But for your case, you can convert your table into a double matrix as
myMatrix = cell2mat(myTable{:});
Then you can do the required calculations.
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!