How can I make true false codition?

조회 수: 1 (최근 30일)
trinasha
trinasha 2021년 9월 30일
댓글: DGM 2021년 10월 4일
Hello, I have witten a code for automating two instruments. In my code I wrote in step by step but the camera is taking image instantly before completing the for loop. and the statement after the catureimage is also being executed instantly. I need to make condition where capture image will be performed when the desired array elements in the for loop becomes true. And i need to make a codition where the stop statement will ocuur if the acquired imge is done. Can anyone please help me with this? I have attached my code here:
dmd = uint8(ones(768,1024)); %dmd mirror matrix model
store_results = uint8(zeros(768,1024)); %dummy matrix to track results i.e. what is positive, what is negative
myapi = alpload();
mydev = alpdevice(myapi);
%mydev.alloc();
%q1
for i = 1:512, j = 1:384; %row coordinate 300-400 previous[1:length(transpose(dmd))]%column coordinate 1: length(dmd);
dmd(i,j) = 255 ; %set coordinate deliberately ON (pixel value??)400-500
%******my frame********
myframe = dmd;%... (your code to create an array 1024x768 of 'uint8') = dmd %in the for loop
mydev.put(myframe);
end
%turn on camera, take image
Image = captureimage();
% % % %stop dmd
mydev.stop();

채택된 답변

DGM
DGM 2021년 10월 1일
편집: DGM 2021년 10월 1일
My understanding is that you're manipulating the mirror array in the DMD and then taking an image. It's not clear why you're repeatedly setting the mirror to different states and then taking the image with the last state. The documentation for alpdevice.put is as useless as I've come to expect:
% Sets pixel to given frame
Which makes it sound like the device needs to be updated elementwise. The usage of obj.put in the other methods (e.g. on and off) suggest that the entire frame is updated at once.
I'm inclined to think that you're trying to do it elementwise, but that's not how the loop is written.
% this loop
for i = 1:512, j = 1:384;
% ...
end
% is the same as this
for i = 1:512
j = 1:384;
% ...
end
% in other words, j is a literal vector and is not part of the iteration
If the entire frame can be updated at once, and the desired area is {1:384,1:512} (a quarter frame), then no loop is needed:
% do device setup ...
dmd = zeros(768,1024,'uint8');
dmd(1:384,1:512) = 255;
mydev.put(myframe);
% turn on camera, take image
Image = captureimage();
% do device release ...
Bear in mind that you're preallocating the dmd array using ones(). That means that the background element value is 1 instead of zero. You might want to be using zeros() instead of ones().
As to whether it's possible to interlock the process by verifying the device state, I don't know. I don't immediately see an obvious way to query the mirror state. There might be, but I don't see it yet.
  댓글 수: 2
trinasha
trinasha 2021년 10월 3일
Thank you. It is now working instantly and simultaneously. Do you have documents of matlab code for DMD? It would be great if you can share the docs.
DGM
DGM 2021년 10월 4일
I don't know anything about working with DMDs. I just found ALPTool via web search and looked at the code synopses.
Like I said, very terse synopses hardly qualifies as "documentation", but that's about what's expected.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by