Need some help

1 visualización (últimos 30 días)
Sarah
Sarah el 1 de Abr. de 2012
Hey guys,
I have some questions that might be relatively simple, but I am not sure how to get about this:
I have a cell array called "TestData", which is a 1x99 cell array. In each cell of TestData is another huge cell array (I'm talking dimensions 85,000x14). So, I have that huge cell array 99 times in the variable TestData. Hope that makes sense.
I have several issues.
1. For each cell (of the 99) of Test Data, there exists some meaningless information that I want to autonomously remove. For example, I would like to remove rows 1 and 2, and columns 9 and 10. How can I do this for each of the 99 subcells in Test Data without manually doing it?
2. I want to save column 1 for each of the 99 cells in TestData into a new variable. How can I avoid manually doing this?
3. I want to convert "TestData" (and all of its contents) from a cell type to a numeric type. How can I effectively do this? If I try something like cell2mat, it gives me an error because cell2mat does not support conversion of cell arrays that have structures or objects within them.
4. Finally, I would like to combine each of the 99 terms in TestData into a single, huge matrix. So, I want the data to be stacked, like so:
TestData(1): 85000x14 TestData(2): 85000x14 (this is combined with TestData(1) to form a new matrix of 170000x14 TestData(3): ... etc etc
I know I am asking for a lot, but I am stuck at this point and I am not really sure how to do the above.

Respuestas (2)

Rick Rosson
Rick Rosson el 1 de Abr. de 2012
Do you know how to write a for loop in MATLAB?
  4 comentarios
Sarah
Sarah el 1 de Abr. de 2012
but thats just the thing, i have trouble formulating the for loops in order to solve my problem...
Geoff
Geoff el 1 de Abr. de 2012
You said that you "keep getting errors here and there". You should post the code that you DO have so we can help you get it working.

Iniciar sesión para comentar.


Kye Taylor
Kye Taylor el 1 de Abr. de 2012
One way to accomplish what I think you're trying to do in items (1) and (2) of your original question is the following:
% row indices to remove
rowIdx2Remove = [1,2];
colIdx2Remove = [9,10];
newC = cell(size(TestData));
for j = 1:length(TestData)
TestData{j}(rowIdx2Remove,:) = []; % remove those rows
TestData{j}(:,colIdx2Remove) = []; % remove those cols
newC{j} = TestData{j}(:,1); % save first column in new cell array
end
However, without more specifics, that may not be helpful. Can you clarify the following?
1.) What do you want to do first, remove rows and cols, or save the first column of each array. 2.) How do you want the first column of each array to be stored? The code above stores it as contents in a new cell array, but you could store them as columns of a new matrix, for instance.
3.) If you want to convert your testData to a numeric type, you'll need to decide on an organization. In particular, you will have to store the data as a three-dimensional numeric array. One organization would be a 85000-by-14-by-99 numeric array, for instance. Is that along the lines of what you you're looking for? Can you add any specifics here?
4.) If you really want a single huge matrix, then the way you're indexing (wanting TestData(1) to be a 85000-by-14) is a little confusing. In a single huge matrix, M, indexing with M(j) will identify only a scalar (1-by-1 number) for all j<=numel(M). Perhaps you really mean a cell? Also, can you clarify what you want in the 3 and 4th elements (I can't tell if the third element is the concatenation of TestData(2) and TestData(3) or a concatenation of TestData(1), TestData(2), and TestData(3)) ?
  1 comentario
Sarah
Sarah el 2 de Abr. de 2012
Hello Kye,
Thanks so much for the help. I implemented your code, and it solves #1 and #2 of my problem very effectively. Thank you, it was very informative and now I know what to do if I ever deal with such a problem again.
As for #3 and 4, maybe this will help:
Now, TestData (after removing rows and cols) is a 1x99 cell array. TestData{1,1} is an 85,000x9 cell matrix. TestData{1,2} is an 80,000x9 cell matrix. The 9 columns stay the same all the way till TestData{1,99}, but the row size is different.
What I want to do is this:
Take the rows from TestData{1,2} and add it to the bottom of the data from TestData{1,1}. Therefore, now we have a matrix that is 165,000x9. Essentially, I am adding 80,000 rows worth of data to TestData{1,1}.
Then, I want to add TestData{1,3} to the bottom of the matrix we just combined earlier in the same fashion...and so on until all of the original 99 elements of TestData have been added to form one large matrix XXXXXX x 9.
I want to transform this final matrix from cell to double, or numeric form.
I hope this is more clear...does this make sense? Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by