the output currently would come out as a vector with 1 column and 7 rows ranging with values ranging from 1-7
Changing array size of user input data
3 次查看(过去 30 天)
显示 更早的评论
I am working on a script to take user input for a number, then create an array with 5 columns from 1 to said number. I am having trouble changing the array from a inputX1 matrix to an inputX5 could someone help me please. I tried to use the reshape function but since the input can be a nonmultiple of 5 the function doesn't work all the time. Here is the code
clear
% clc
name=input('Enter name:','s');
% Ask user to input name
number=input('Enter a whole number between 1 and 100:');
% Ask user for a whole number between 1 and 100
while number<1 || number>100 || round(number)~=number
% a while function that performs actions under if number doesn't meet
% specifications
display('Not a valid number please try again')
number=input('Enter a whole number between 1 and 100:')
end
% End while loop
array=[1:number];
% Create array from 1 to input number
entryposition=0;
% Set entry position to 0 for start of loop
disp('Thank you!')
disp(name)
disp(array')
采纳的回答
Ridwan Alam
2020-1-29
编辑:Ridwan Alam
2020-1-29
myCell = {}; k = 0;
for i = 1:5:number
k = k + 1;
myCell{k,1} = i:min(i+4,number);
end
writecell(myCell,fullfile(myFolder,'myFile.xls'))
p.s: this is not an "optimal" solution.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!