cell-array

Count unique rows in a cell full of vectors

为君一笑 提交于 2019-12-23 12:24:20
问题 I have a cell in MATLAB where each element contains a vector of a different length e.g. C = {[1 2 3], [2 4 5 6], [1 2 3], [6 4], [7 6 4 3], [4 6], [6 4]} As you can see, some of the the vectors are repeated, others are unique. I want to count the number of times each vector occurs and return the count such that I can populate a table in a GUI where each row is a unique combination and the date shows how many times each combination occurs. e.g. Count "[1 2 3]" 2 "[6 4]" 2 "[2 4 5 6]" 1 "[7 6 4

Create relation matrices from a given cell-array of strings (Matlab)

喜夏-厌秋 提交于 2019-12-23 05:08:00
问题 I have 2 sequences in a cell-array : Input_cell= {'ABC','ACB'} S1= 'ABC' % which means A<B<C S2= 'ACB' % which means A<C<B I want to convert each of the strings in the Input_cell into a matrix M[i,j] which has to satisfy those conditions : M[i,j] , M[j,i] are random M[i,i] =0.5 M[i,j] + M[j,i] = 1 M[i,j] < M[j,i] % For example: if A<B then M[A,B] < M[B,A] %// For example: if we have S1 = 'ABC' (which means `A<B<C`), the M1 matrix will be expected as follows: A B C A 0.5 0 0 B 1 0.5 0 C 1 1 0

display all elements in a nested cell array (with character entries)

狂风中的少年 提交于 2019-12-23 04:45:15
问题 I have the following: a = {1x1 cell} {1x1 cell} {1x1 cell} {1x1 cell} where: a{:} ans = 'a' ans = 'a' ans = 'c' ans = 'a' I want to have the characters: a a c a Since I need the characters to print using fprintf fprintf won't accept a{:} If I do a{1}{:} will consider only the first character a How to fix this? Thanks. 回答1: If you only need the character vector 'aaca', you can use this: a = {{'a'}, {'a'}, {'c'}, {'a'}}; a_CharVector = cellfun(@(x) char(x), a); If you want the character vector

Subsref with cells

那年仲夏 提交于 2019-12-21 17:53:41
问题 This issue appeared when I was answering this question. It should be some stupid error I am doing, but I can't get what error it is… myMatrix = [22 33; 44 55] Returns: >> subsref(myMatrix, struct('type','()','subs',{{[1 2]}} ) ); ans = 22 44 While using it with cells: myCell = {2 3; 4 5} Returns: >> subsref(myCell,struct('type','{}','subs',{{[1 2]}} ) ); ans = 2 % WHATTT?? Shouldn't this be 2 and 4 Matlab?? Checking the subsref documentation, we see: See how MATLAB calls subsref for the

MATLAB “bug” (or really weird behavior) with structs and empty cell arrays

别说谁变了你拦得住时间么 提交于 2019-12-21 11:34:09
问题 I have no idea what's going on here. I'm using R2006b. Any chance someone out there with a newer version could test to see if they get the same behavior, before I file a bug report? code: ( bug1.m ) function bug1 S = struct('nothing',{},'something',{}); add_something(S, 'boing'); % does what I expect add_something(S.something,'test'); % weird behavior end function add_something(X,str) disp('X='); disp(X); disp('str='); disp(str); end output: >> bug1 X= str= boing X= test str= ??? Input

What is the equivalent to a Matlab cell array?

非 Y 不嫁゛ 提交于 2019-12-21 09:32:47
问题 I am new to Python and trying to create something equivalent to Matlab's "cell array". Lets say I have 100 customers index 'C001', 'C002' etc. and I have different data for each customer: Size of premises in square meters [real number] categorical data showing whether they are 'commercial', 'residential' or 'other' hourly time series of their electricity consumption in 2014 i.e. datetime-indexed array of 8760 real values What is the best way to buildsuch a dataset in Python 2.7 that combines

What is the equivalent to a Matlab cell array?

旧街凉风 提交于 2019-12-21 09:30:46
问题 I am new to Python and trying to create something equivalent to Matlab's "cell array". Lets say I have 100 customers index 'C001', 'C002' etc. and I have different data for each customer: Size of premises in square meters [real number] categorical data showing whether they are 'commercial', 'residential' or 'other' hourly time series of their electricity consumption in 2014 i.e. datetime-indexed array of 8760 real values What is the best way to buildsuch a dataset in Python 2.7 that combines

How do I replace an element from a cell array?

牧云@^-^@ 提交于 2019-12-20 05:45:25
问题 I have a cell array: A = {NaN, ‘k’, ‘m’, ‘n’} I want to replace all but the 3rd element of A with NaNs to obtain B = {NaN, NaN, ‘m’, NaN} Please, any help/suggestions on how I could go about this? Also, is it possible to do this with a single line of code? 回答1: You could create a new array of all NaN's and then replace the third element with the value from the initial cell array B = num2cell(nan(size(A)); B(3) = A(3); Alternately, you can overwrite the other values with: B = A; B([1 2 4]) =

How to append in .mat file row or columnwise cellmatrix

一笑奈何 提交于 2019-12-19 10:19:49
问题 I am running a simulation where i generate huge 2d sparse matrices and hence i use FIND function to only store nonzero values with their indices. Now for each iteration of for loop i generate such matrix and because they are all of different length I use cell-array to store these configurations. But for large simulations even squeezed-off format of cell-array crosses its limits of memory and hence i want to write these cell-array while running the code i.e. for each iteration append a new

“Flattening” a cell array

孤街醉人 提交于 2019-12-19 05:21:06
问题 I have created a function which takes vectors for input variables and returns a cell array for each set of inputs. The final output variable (out) seems to consist of a 2x1 cell containing two 1x5 cells. I have provided a screenshot of this below: I am just trying to figure out how to flatten the cell array (out) to be a 2x5 cell array. 回答1: One way to achieve that would be - vertcat(cell_array1{:}) 回答2: If your cell has unequal number of elements in each row , maybe this might work better