How to use IF with @(block_struct) function
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saud Alfalasi
am 22 Nov. 2020
Bearbeitet: Saud Alfalasi
am 24 Nov. 2020
fun2 = @(block_struct) ...
if block_struct.data < 100
std2(block_struct.data) * (block_struct.data));
end
Doesnt work.
I actually want to manipulate individual elements of my block
blocks made of 8x8 values ranging from 0-255
2 Kommentare
Geoff Hayes
am 22 Nov. 2020
Saud - can you show us what the block_struct looks like with respect to attributes/properties? Presumably it has a data field. It isn't clear to me why you are doing
fun2 = @(block_struct) ...
where block_struct is the input to some function. Or are you hoping that all of the code
fun2 = @(block_struct) ...
if block_struct.data < 100
std2(block_struct.data) * ones(size(block_struct.data));
end
is an anonymous function? If so, then I don't think that the above is valid...
Akzeptierte Antwort
Athul Prakash
am 24 Nov. 2020
Hi Saud,
Since blockproc uses anonymous functions, you may save your multi-line function into a script, say myFunc.m and then pass @myFunc to your blockproc call.
You can find block_struct structure described in the following doc (under More About section): 'blockproc' Documentation.
You may work out a way to manage the sequence artificially using some of those fields. For example, using block_struct.location to skip processing the 2nd block:
function out = myFunc(block_struct) % size would be 100x100
if(block_struct.location(2)==101)
% skipping the 2nd block.
out = block_struct.data;
else
% code for processing every other element
end
end
Hope it helps!
3 Kommentare
Athul Prakash
am 24 Nov. 2020
Glad to help. Have you considered accepting this answer? On this platform, 'Accepting' is considered the highest form of validation for any answer. In addition to expressing the Questioner's satisfaction/gratitude, Accepting also makes an answer more discoverable to the rest of the community browsing this platform.
Not to blow my own trumpet though ;).
Cheers!
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!