# matlab table selecting values

10 vues (au cours des 30 derniers jours)
Emily Platt le 8 Mai 2021
Commenté : Emily Platt le 13 Mai 2021
i want to use a for loop to go through the values in a table with 10 rows and 1 column one by one. so far my code reads the whole table at the same time
thanks
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

Image Analyst le 8 Mai 2021
Emily, try this:
% Generate sample data:
v1 = rand(10, 1);
v2 = rand(10, 1);
charVector = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j'];
% Create table
t = table(v1, v2, charVector)
% Loop over all rows in the table.
for row = 1 : height(t)
fprintf('For row %2d, v1 = %.2f, v2 = %.2f, c = %s\n', ...
row, t{row, 1}, t{row, 2}, t{row, 3});
end
% Generate sample data:
v1 = rand(10, 1);
% Create table
t = table(v1)
% Loop over all rows in the table.
for row = 1 : height(t)
fprintf('For row %2d, v1 = %.2f\n', ...
row, t{row, 1});
end
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Emily Platt le 13 Mai 2021
perfect thank you

Connectez-vous pour commenter.

### Plus de réponses (1)

Tala le 8 Mai 2021
I am not sure what do you mean by go through the values. This should solve your problem you:
myCell = {1; 2; 3;4;5;6;7;8;9;10};
for i=1:height(myCell)
D=myCell{i};
display(D)
end
##### 3 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Tala le 8 Mai 2021
This is what I see, running the code I posted. I see one value at a time. I might be missing something tho!
Can you give me an example? What do you expect to see?
Image Analyst le 8 Mai 2021
She wants a table, not a cell array.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Tables 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