Table not structuring the way I want

조회 수: 1 (최근 30일)
Jack Smillie
Jack Smillie 2019년 4월 30일
답변: Star Strider 2019년 4월 30일
I want to input information so that it creates a x by 7 table, where x depends on the number inputed at the beginning. However, it keeps creating a 1 by 7 table but in the table each column has x number of values instead of moving down to the next row for each value. I've tried to change things but I also get a "Conversion to double from cell is not possible" error when I swap my variables to () instead of {} so I'm stuck.
answerTotalNoSpaces=inputdlg('Enter','Total Number Of Spaces');
totalNoSpaces=str2double(answerTotalNoSpaces{1});
SpaceType=(totalNoSpaces);
FloorNumber=(totalNoSpaces);
SpaceX=(totalNoSpaces);
SpaceY=(totalNoSpaces);
SpaceZ=(totalNoSpaces);
SpaceCoordX=(totalNoSpaces);
SpaceCoordY=(totalNoSpaces);
for i=1:1:totalNoSpaces
list={'Residential','Office','Education','Toilet','Storage'};
[selectionindex,ok]=listdlg('ListString',list);
if ok
SpaceType(i)=list(selectionindex);
end
answerFloorNumber=inputdlg('Enter','Floor Number');
FloorNumber(i)=str2double(answerFloorNumber{1});
answerSpaceX=inputdlg('Enter','Space X distance (m)');
SpaceX(i)=str2double(answerSpaceX{1});
answerSpaceY=inputdlg('Enter','Space Y distance (m)');
SpaceY(i)=str2double(answerSpaceY{1});
answerSpaceZ=inputdlg('Enter','Space Z distance (m)');
SpaceZ(i)=str2double(answerSpaceZ{1});
answerCoordX=inputdlg('Enter','Space X coord');
SpaceCoordX(i)=str2double(answerCoordX{1});
answerCoordY=inputdlg('Enter','Space Y coord');
SpaceCoordY(i)=str2double(answerCoordY{1});
end
buildingTable=table(SpaceType,FloorNumber,SpaceX,SpaceY,SpaceZ,SpaceCoordX,SpaceCoordY);

채택된 답변

Star Strider
Star Strider 2019년 4월 30일
The table function works best with column vectors for each variable. Your code creates row vectors.
The easiest way to correct this (creating column vectors) is to add a default second subscript:
FloorNumber(i,:) = ...
SpaceX(i,:) = ...
and so for the others.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by