필터 지우기
필터 지우기

Is it possible to take inputs as several sets?

조회 수: 1 (최근 30일)
DIJESH
DIJESH 2014년 5월 28일
댓글: DIJESH 2014년 5월 29일
prompt = {'Enter the co-ordinates of points eg (x1,y1,z1,x2,y2,z2,.....: '};
title = 'Environmental forces';
answer = inputdlg(prompt,title);
forces = str2num(answer{:});
The above code will read any number inputs given by the user. Since they are co-ordinates what if we want to work in such a way that it reads the value in set of 3 i.e. the first three values entered will be x1, y1, z1 then x2, y2, z2... is it possible?

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 5월 28일
Since you are assuming that every triplet corresponds to an (x,y,z) coordinate, then just extract all the x-, y- and z-coordinate into separate vectors:
x = forces(1:3:end); % x-coordinates are 1,4,7,…
y = forces(2:3:end); % y-coordinates are 2,5,8,…
z = forces(3:3:end); % z-coordinates are 3,6,9,…
The code would need some logic to ensure that the lengths of all three vectors are the same (for the case where the user did not enter in a multiple of three values):
if length(x)~=length(y) || length(x)~=length(z)
% do some handling for case where vectors are not the same length
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by