Effacer les filtres
Effacer les filtres

For Loop for Cell?

1 vue (au cours des 30 derniers jours)
cestcandice
cestcandice le 7 Juin 2017
Commenté : cestcandice le 7 Juin 2017
For this program, the user will input any number they want in a dialog box, and from that I need to make an array from 1 to that number. However, all the combos and for loops I've tried so far haven't worked! Please help!!!
This code for example, for some reason, lists the numbers between 1 and 51, instead of 1 and 12 like it's supposed to...
%This is the dialog box where the user can enter any number. It's defaulted at 12
prompt={'Enter any value'};
name = 'Any Value';
defaultans = {'12'};
options.Interpreter = 'tex';
B = inputdlg(prompt,name,[1 40],defaultans,options);
% here I was trying to get the value out of a cell and into a matrix
a=cell2mat(B)
% Here I tried to use a for loop to get a matrix between 1 and (in this case) 12
for k=a
a=a+1
k=1:a
end

Réponse acceptée

Akira Agata
Akira Agata le 7 Juin 2017
The last half of your code should be revised, like:
% Get the value out of a cell
a = str2num(cell2mat(B));
% Make an numeric array from 1 to a
K = 1:a;
  1 commentaire
cestcandice
cestcandice le 7 Juin 2017
This is so simple and I struggled with it for hours! Wow... Thank you,I really appreciate it.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by