I'm trying to create a function in where a user can input 1 to have an excel file of two lines of data read as (x,y) coordinates. But also that the user can select 2 so they can enter their own (x,y) coordinates but in comma-separated pairs. Like pairs in 2 rows. Whenever I try to enter values for z I only get an empty matrix and idk how to actually fix that. Would I need to do a loop or another function like creating a cell array? (After the matrix is created I'm also hoping to just read each row and attach them to either x and y).
if true
% code
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [x,y] = BB_GrabInputData(z)
%Creates an output of data depending on what the user inputs for vectors
% User must select either file or manual data points in an even-numbered
% vector
A=0;
while A == 0
User_DataSelect=input('<1>Read in a data file or <2>Enter data points by hand?' );
if User_DataSelect==1
z = xlsread(strinput('Enter in your file name'));
x = z(:,1);
y = z(:,2);
A= A + 1;
elseif User_DataSelect==2
disp('Enter in your data points in comma-seperated pairs.\n Press <Enter> without typing any numbers when you are done entering the data.\n')
z = input('');
z = z(end) + z
A=A+1;
else
disp('Error: Invlalid User Input') %Detects when an invalid selection occurs and the loop repeats
A=0;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

댓글 수: 2

Stephen23
Stephen23 2018년 2월 27일
Rather than using input it would be much simpler to call uitable.
Brevon Baker
Brevon Baker 2018년 2월 27일
The user needs to be able to input their data points in comma-separated pairs.

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2018년 2월 27일
편집: Stephen23 2018년 2월 27일

0 개 추천

x = [];
y = [];
pmt = 'Enter comma-separated pairs. Press <Enter> with no data to exit. ';
while true
str = input(pmt,'s');
if numel(str)
tmp = sscanf(str,'%f,%f');
x(end+1) = tmp(1);
y(end+1) = tmp(2);
else
break
end
end

댓글 수: 2

Brevon Baker
Brevon Baker 2018년 2월 27일
I can't seem to even run this program.
@Brevon Baker: I fixed the start conditions, it works now:
Enter comma-separated pairs. Press <Enter> with no data to exit. 1,2
Enter comma-separated pairs. Press <Enter> with no data to exit. 3,4
Enter comma-separated pairs. Press <Enter> with no data to exit. 5,6
Enter comma-separated pairs. Press <Enter> with no data to exit.
>> x
x =
1 3 5
>> y
y =
2 4 6

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

제품

질문:

2018년 2월 27일

편집:

2018년 2월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by