Turning a list of answers into a single array
20 次查看(过去 30 天)
显示 更早的评论
I would like to know how I can(if I can) put my answers into a single matrix/array... for example: ans=12 ans=13 and=73 ans=59 and so on, and would like it in the form [12;13;73;59]
2 个评论
采纳的回答
Image Analyst
2014-10-20
If you want to capture the output of some operation, then you need to accept it into some variable. If you don't and just let it spew out "ans = ...." to the command window then you can't put those into a variable unless you used diary() and then parsed the file - a major pain.
2 个评论
Image Analyst
2014-10-20
编辑:Image Analyst
2014-10-20
Regarding your loop you just added, to get the second column of y into results, do this:
results = y(:, 2);
Now, to print out results where the first column of y equals some ID number:
rowsToPrint = y(:, 1) == ID; % Logical index
fprintf('%f\n', results(rowsToPrint));
Note: no for loop is needed at all.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!