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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by