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
采纳的回答
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 个评论
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
As you can see, if I do for example regionprops(BW,"centroid")
it gives me this ... but like 15 times the same table ...

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
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.
OK, so you need to improve your segmentation algorithm if you think it's really there but your current algorithm is not finding it.
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.
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
