How can I find a specific value of member in cell array

2 visualizzazioni (ultimi 30 giorni)
hello,
I have a cell array (100 * 50 cell), each cell contain several variables, like (Ptx in subcarrier(vector 100 valuse) , Position of subchannels(vector 10 valuse) , interfernce(vector 10 valuse) , SubFrame).
I need to find all cells that have SubFrame equal 1.
VH = cell(100,50);
index = find([VH{:,:}.SubFrame] == 1); % but it doesnt work??
What can i do? THanks in advance.
  4 Commenti
saif sabeeh
saif sabeeh il 24 Dic 2018
sorry my code not finished yet. I divided the channel to subchannels with specific number of resource blocks distributed through a period. Each subchannel has a subframe number(time in period) and subchannel number(in the subframe). I am trying to calculate the inerefernce between two transmiters that use the same subchannel and same subframe.
My question is how can make a search with conditions, number of subframe and number of subchannel is same, to find transmiters that interefers with eachother.
for example I have 100x50 cells and each cell has (subframe number and subchanne number( I want to process)), and some other members.
I need to find for example cell with subframe = 1.
Guillaume
Guillaume il 24 Dic 2018
Modificato: Guillaume il 24 Dic 2018
So, your cells do not contain structures (at least some of them don't) and Matt's and my assumption were wrong. The problem is we still have no idea what is in each cell of the cell array.
Remember that we have absolutely no idea what you're starting with. We don't know what the channels mean. Matlab does not a channel data type. We have absolutely no idea what resource blocks are.
You either need to show some code as requested, or better attach a simple mat file containing that VH cell array.

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 24 Dic 2018
Modificato: Image Analyst il 24 Dic 2018
A cell cannot contain more than one variable. It can contain only 1. It cannot contain 3 vectors and a scalar unless they parts of a single variable like a structure or table variable. So you could have, say, a structure str, and str had 3 fields, each of which is a 100 or 10 element vector, and one field that is a scalar called SubFrame. Not sure if there is a cryptic way of getting the SubFrame values using cellfun but check the other answers. Below is a brute force way of getting SubFrame
[rows, columns] = size(VH)
allSubFrames = zeros(rows, columns); % Preallocate our output array.
for col = 1 : columns
for row = 1 : rows
thisCellsContents = VH{row, col}; % Extract structure
allSubFrames(row, col) = thisCellsContents.SubFrame; % Extract SubFrame from the structure
end
end
Again, the above assumes your cell contains a structure, not a table.
To find all cells that contain the same SubFrame, you can use unique:
uniqueSubFrames = unique(allSumFrames(:))
Then you can use a loop to check each one number to find out what cell(s) that number appears in.
for k = 1 : length(uniqueSubFrames)
thisNumber = uniqueSubFrames(k);
[sfRows, sfColumns] = find(allSumFrames == thisNumber);
% Now do something with that information....not sure what....
end
  4 Commenti
Image Analyst
Image Analyst il 24 Dic 2018
Yes you could do the loop that way, but with the 2-D loop I used, the answers are in the same row and column as the input instead of in a linear array, and that may be helpful depending on what you want to do with the information.
Well maybe not cryptic to you but honestly even to me, and even more so to beginners, a simple for loop is often easier to understand and more intuitive than functions like cellfun(), arrayfun(), blockproc(), accumarray(), im2col() and other types of functions that are more compact. So being easier to understand and maintain is often more important than compactness or efficiency (run time).
Guillaume
Guillaume il 24 Dic 2018
With my loop, the answer is in a 2d array if the input is 2d, in a 3d array if the input is 3d, etc. (same as with cellfun)

Accedi per commentare.

Più risposte (2)

Matt J
Matt J il 24 Dic 2018
Modificato: Matt J il 24 Dic 2018
subframes=cellfun(@(c) c.Subframe, VH);
index=find(subframes==1);

Guillaume
Guillaume il 24 Dic 2018
It's really not clear from your description but it sounds like each cell of the cell array contains a scalar structure. If that's not the case, then you need to tell us exactly what is in the cells. It's certainly not variables. If that is the case, then:
  • Why aren't using a 2D structure instead of a cell array of scalar structures? It would make everything simpler
  • The way to do it with your current storage is:
find(cellfun(@(s) s.SubFrame == 1, VH))
  • Do you actually need the find. More often than not, the logical array that you pass to find is enough. e.g. if you want to keep only those elements of VH where the subframe is 1. then:
filteredVH = VH(cellfun(@(s) s.SubFrame == 1, VH)); %no need for find
  1 Commento
saif sabeeh
saif sabeeh il 24 Dic 2018
Guillaume
, Matt J . Thank you for response. I tried the code you mentioned but the error was:
Struct contents reference from a non-struct array object.
to more clear to my question:
VH{i, j}.SubChannel, 20
VH{i, j}.SubFrame, 3
VH{i, j}.ChanGain, 70.6
VH{i, j}.dists, 16
this example for one cell, I have (100 * 50) cells. I would like to find all cells that have the same
value of SubChannel and SubFrame.
Thank you

Accedi per commentare.

Tag

Prodotti


Release

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by