Save data from cycle into one table
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello, I have a code where the aotput is x and y, but I would like to store this data into one table or varieble. Problem is, that it gives me data only in one cyklus and it gives me it 15 times the same data, and than for h=2 it gives me 14 times the same value .. and so on
I would like to get one x and y from every loop and save it in one table or whatever, so after the code is ended, I would like to have everything in one place, if you understand. Now it gives me separately for every loop.
Thank you so much
採用された回答
Image Analyst
2022 年 11 月 12 日
x and y are the locations of all the white pixels in the image. There will likely be tens of thousands of values in each vector. Did you want the x and y of the blob centroid(s) instead?
What if you just stored the x and y in a cell array
ca{h, 1} = x;
ca{h, 2} = y;
Not sure why you have a loop within a loop but maybe you want i instead of h in the lines of code above.
Can we run your code with the demo that ships with MATLAB, rhinos.avi, or do we need your specific video to be attached?
8 件のコメント
Eliska Paulikova
2022 年 11 月 13 日
Well we can try it, because I do not know what to do next.
Yes I have two loops because I need to apply the segmentation and this was only way I can do it, because I do not have so much experience with matlab.
We can try it, but use the demo, it will work, but you do not see the result I need. But never mind, I only want to solve the problem with many datas in one cycle and how to save the data.
Thank you for helping me
Eliska Paulikova
2022 年 11 月 13 日
As you can see, if I do for example regionprops(BW,"centroid")
it gives me this ... but like 15 times the same table ...

Image Analyst
2022 年 11 月 13 日
I don't know what you want. You just say you want the x and y coordinates of the segmented image. This is a classic XY Problem.
I told you how do get x and y for all white pixels in the segmented image. But since you came back I presume that is not what you wanted. You also got the centroids but I don't understand your pictures. Centroids are a 2 element vector, not a 5 by 1 vector. You have two structures, each with a field called Centroid but it has only one number in it. I don't know how you got those. What you should do is
props = regionprops(BW, 'Centroid');
xyCentroids = vertcat(props.Centroid)
So let's say that you are able to do whatever it is that you think you want (finding all x,y or just the x,y of the blob centroids, or whatever). Then what? What will you do with that information? Why do you even care about measuring it?
Also, please explain your thinking about why you have a whilte loop inside a for loop inside a while loop instead of a single for loop over the number of frames
for h = 1 : 2000 : vid.NumFrames
Eliska Paulikova
2022 年 11 月 13 日
You are right I change it, now I have while cycle and for cycle .. I also get the x and y values.
Now the problem is, that I getting this data according to image segmentation, So if the segmentation is not good, it gives me NaN ... and I can to save it into table, because there is no value.
Image Analyst
2022 年 11 月 13 日
OK, so you need to improve your segmentation algorithm if you think it's really there but your current algorithm is not finding it.
Eliska Paulikova
2022 年 11 月 13 日
Thank you, when when I did it.
How can I store all this value from every cycle into one table. Because I will get many values but only for one cycle. I would like to store them together.
Image Analyst
2022 年 11 月 13 日
You can ask regionprops for a table. Then you can append the table for this frame to the growing master table.
thisTable = regionprops('table', BW);
if frameNumber == 1
masterTable = thisTable;
else
masterTable = [masterTable; thisTable];
end
Eliska Paulikova
2022 年 11 月 14 日
編集済み: Eliska Paulikova
2022 年 11 月 14 日
Thank you so much, I appreciate it a lot
It helped
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Preview and Device Configuration についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
