0
votes

I have a numeric array sized 1000x1 which have values 0 and 1, called conditionArray. I have a cell array called netNames with the same size (1000x1) and its cells contain string values (which are name of some circuit nets). I want to extract net names which from netNames which their pairwise condition bit is 1 in conditionArray. E.g. if conditionArray(100) is equal to extract its net name from netNames{100}.

Output of this process can be stored in an string array or cell array. Are there any ways to do this operation with pairwise operations or I should use a for statement for this?

2
Can you provide a MCVE ?Paolo
@UnbearableLightness protip: [mcve]: minimal reproducible exampleAnder Biguri
@AnderBiguri Ah, neat. Cheers :)Paolo
Why does netNames(conditionArray) not work?Wolfie

2 Answers

0
votes

You shall check out cellfun in Matlab anytime you want to manipulate each element inside a cellarray without using a for loop.

0
votes

As I understand, you have:

N = 1000;
% an array with 0s and 1s (this generates random 0s and 1s):
conditionArray = randi([0,1],N);
% a cell array with strings (this generates random 5-character strings):
netNames = cell(N);
netNames = cellfun(@(c)char(randi([double('a'),double('z')],1,5)), netNames, 'UniformOutput',false);

To extract the elements from netNames where conditionArray is 1, you can do:

netNames(conditionArray==1)

This uses logical indexing into the cell array.