cell-array

How to delete element from cell arrays after comparisons without causing cell arrays to get empty?

萝らか妹 提交于 2020-01-16 18:09:47
问题 I created 1D array which shows words and in which sentences they occur. After that I took the intersection to show which word occurs with which each of other remaining words in sentence: OccursTogether = cell(length(Out1)); for ii=1:length(Out1) for jj=ii+1:length(Out1) OccursTogether{ii,jj} = intersect(Out1{ii},Out1{jj}); end end celldisp(OccursTogether) the output of above code is as below: OccursTogether{1,1} = 4 11 14 OccursTogether{1,2} = 1 OccursTogether{1,3} = [] OccursTogether{1,4} =

How to delete element from cell arrays after comparisons without causing cell arrays to get empty?

社会主义新天地 提交于 2020-01-16 18:06:27
问题 I created 1D array which shows words and in which sentences they occur. After that I took the intersection to show which word occurs with which each of other remaining words in sentence: OccursTogether = cell(length(Out1)); for ii=1:length(Out1) for jj=ii+1:length(Out1) OccursTogether{ii,jj} = intersect(Out1{ii},Out1{jj}); end end celldisp(OccursTogether) the output of above code is as below: OccursTogether{1,1} = 4 11 14 OccursTogether{1,2} = 1 OccursTogether{1,3} = [] OccursTogether{1,4} =

Plotting a cell array

为君一笑 提交于 2020-01-16 03:59:06
问题 I need to plot a cell array with the following format in Matlab: {[vector1], [vector2], ...} Into a 2D graph with the index of the vector as the y and the vector as the x ([vector1], 1), ([vector2], 2), ... 回答1: Here's a simple option: % some arbitrary data: CellData = {rand(10,1)*50,rand(10,1)*50,rand(10,1)*50}; % Define x and y: x = cell2mat(CellData); y = ones(size(x,1),1)*(1:size(x,2)); % plot: plot(x,y,'o') ylim([0 size(x,2)+1]) so you plot each vector of x on a separate y value: It will

Proper way of accessing field of a 1xn stuct

我们两清 提交于 2020-01-15 12:15:21
问题 I have looked for the proper way to access a given field of a struct and the manual and online searches didn't help. Formally, let MyStruct be a 1xn struct variable. It's easy to list all the elements stored in a field with: MyStruct.Thisfield ans = 0.7010 ans = 0.310 ans = 0.444 etc. Now the only way I found to be able to access an element of this is to use a temporary variable, e.g. temp={MyStruct.Thisfield} and then temp{1,2} etc. I think it's clumsy but can't figure out what else to do.

How to read multiple files into a single cell array?

a 夏天 提交于 2020-01-14 05:44:26
问题 I have a large dataset split into 5 files (each has 15000 attributes, first file contains header (attribute names) and 9999 records, and the other 4 contain 10000 records). Using textscan, I have created 5 cell arrays which have to be merged and don't know whether this approach is appropriate or it would be better to directly read all 5 files into single cell array. Anyway I would be thankful if anyone of you could show the way to merge several cell arrays into single cell array or read

Opening a mat file using h5py and convert data into a numpy matrix

允我心安 提交于 2020-01-06 19:52:28
问题 I have a mat file which contains 2 different cells containing matrices of different size. I need to convert that data into a numpy array using h5py for an experiment (I'm new in h5py. I thought it was as easy as it is explained here Reading the file works well, putting the data in the numpy array also works well, but I need the value representation of each position inside each matrix inside each cell, taking into account that when I print for example np.array(x[0][1]) , I receive just the

Matrix manipulation to extract certain sub columns

匆匆过客 提交于 2020-01-05 13:06:45
问题 M = [1007 1007 4044 1007 4044 1007 5002 5002 5002 622 622; 552 552 300 552 300 552 431 431 431 124 124 ; 2010 2010 1113 2010 1113 2010 1100 1100 1100 88 88; 7 12 25 15 12 30 2 10 55 32 12] X = {[2 5 68 44],[2 10 55 9 17],[1 55 6 7 8 9],[32 12]} A = [1007 4044 5002 622 552 300 431 124 2010 1113 1100 88 7 25 2 32 12 12 10 12 15 55 30 ] A is an entity to explain what I want. A contains unique column vectors of M(1:3,:) , in addition to the corresponding values in M(4,:) A(1:3,:) = unique(M(1:3,:

formatting character arrays [duplicate]

不羁的心 提交于 2020-01-05 07:23:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Counting values by day/hour with timeseries in MATLAB This is an elementary question, but I cannot find it: I have a 3000x25 character array: 2000-01-01T00:01:01+00:00 2000-01-01T00:01:02+00:00 2000-01-01T00:01:03+00:00 2000-01-01T00:01:04+00:00 These are obviously times. I want to reformat the array to be a 3000x1 array. How can I redefine each row to be one entry in an array? (Again, this is simple, I'm sorry)

Reshaping nested struct arrays to cell array having elements with different sizes

一曲冷凌霜 提交于 2020-01-04 02:19:05
问题 I have a similar question to my previous one. This time the form of the nested structure looks like this: Sizes = [2, 5, 8, 6, 3]; cells = 5; for i = 1:cells for j = 1:Sizes(i) a(i).b.c(j).d = rand(1,1); end a(i).b.Size = Sizes(i); end Again I would like to put all the d values of a(:).b.c(:) into a single cell array that contains 1 x cells cells. Here is my solution using cellfun but I would like to avoid this function: ab = [a.b]; abc = {ab.c}; abcd = cellfun(@(x) [x.d], abc, 'UniformOutput

Convert cell to double

好久不见. 提交于 2020-01-01 08:59:10
问题 >> C = [{1} {2} ; {'@CF'} {2}] C = [ 1] [2] '@CF' [2] >> whos C Name Size Bytes Class Attributes C 2x2 478 cell How can I convert C into double so that: >> C C = 1 2 NaN 2 I've tried str2double(C) . It returns: NaN NaN NaN NaN 回答1: Find the non numeric values with isnumeric, queried by cellfun. Use that with logical indexing to extract the numeric values: C = [{1} {2} ; {'@CF'} {2}]; isnum = cellfun(@isnumeric,C); result = NaN(size(C)); result(isnum) = [C{isnum}]; 回答2: C = [{1} {2} ; {'@CF'}