cell-array

How to find the common elements of 2 cell arrays that contain randperm elements?

狂风中的少年 提交于 2019-12-02 14:01:07
问题 I have two cell arrays which may not be of the same size. Elements of cell arrays is randperm of an integer number. randperm data Type is double array. How can I find common elements of two cell arrays? For example: Q1 = {[1 2 3 4], [3 2 4 1], [4 2 1 3]} Q2 = {[2 4 3 1], [1 2 3 4], [1 2 4 3]} As I said elements of cell arrays are randperm . I want the output of above example be "Element-1 of Q1 i.e. [1 2 3 4] since it is also present in Q2 . Note: Cell Arrays may have different number of

How do I create a 50x3 cell array from a 50x3 matrix. Keep just getting a 1x1 cell array with a 50x3 submatrix?

孤街浪徒 提交于 2019-12-02 13:30:29
问题 Using this code but it keeps just giving me a 1x1 cell array mynewcellarray = mat2cell(oldmatrix, 50, 3) 回答1: You should use num2cell: mynewcellarray=num2cell(oldmatrix) 来源: https://stackoverflow.com/questions/21336105/how-do-i-create-a-50x3-cell-array-from-a-50x3-matrix-keep-just-getting-a-1x1-ce

Reordering Cell Array by Array of Indices

大城市里の小女人 提交于 2019-12-02 13:12:55
Suppose I have a cell array x and an integer array y : x = {'apple', 'orange', 'banana', 'pear'}; y = [2 4 3 1]; In fact, y represents indices of x . I want to now create a cell array z with the elements of x reordered as specified by the order of these indices. This would give me: z = {'orange', 'pear', 'banana', 'apple'}; Can I do this in one line without having to loop through each element and place it in z in turn? z = x(y); Because StackOverflow requires answers at least 30 chars long, this sentence was created as a filler. That means: put in z the cell array with elements frrm x , that

How do I replace an element from a cell array?

感情迁移 提交于 2019-12-02 10:08:07
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? 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]) = {NaN}; As far as a single line of code, the number of lines is quite irrelevant. What's important is

Find string in cell array with elements of different types

て烟熏妆下的殇ゞ 提交于 2019-12-02 09:25:10
问题 I have a function that takes variadic arguments. These arguments are parameter-value pairs, so varargin is a cell array in which every odd-indexed element is a string (the parameter), but the even-indexed elements can be a string, number, or cell array of strings. I want to find the index of a particular string in varargin . I have a working solution, but it uses arrayfun twice; is there a cleaner/faster/more effective way of find a string in such a cell array? The resulting index will be

How to find the common elements of 2 cell arrays that contain randperm elements?

我与影子孤独终老i 提交于 2019-12-02 07:15:30
I have two cell arrays which may not be of the same size. Elements of cell arrays is randperm of an integer number. randperm data Type is double array. How can I find common elements of two cell arrays? For example: Q1 = {[1 2 3 4], [3 2 4 1], [4 2 1 3]} Q2 = {[2 4 3 1], [1 2 3 4], [1 2 4 3]} As I said elements of cell arrays are randperm . I want the output of above example be "Element-1 of Q1 i.e. [1 2 3 4] since it is also present in Q2 . Note: Cell Arrays may have different number of columns... Vertically concatenate the matrices inside the cell arrays and use intersect with the 'rows'

Find string in cell array with elements of different types

时光总嘲笑我的痴心妄想 提交于 2019-12-02 04:42:15
I have a function that takes variadic arguments. These arguments are parameter-value pairs, so varargin is a cell array in which every odd-indexed element is a string (the parameter), but the even-indexed elements can be a string, number, or cell array of strings. I want to find the index of a particular string in varargin . I have a working solution, but it uses arrayfun twice; is there a cleaner/faster/more effective way of find a string in such a cell array? The resulting index will be used to remove that element and the following one from varargin . I would like to minimize creation of new

How do I create a 50x3 cell array from a 50x3 matrix. Keep just getting a 1x1 cell array with a 50x3 submatrix?

…衆ロ難τιáo~ 提交于 2019-12-02 03:39:11
Using this code but it keeps just giving me a 1x1 cell array mynewcellarray = mat2cell(oldmatrix, 50, 3) phyrox You should use num2cell : mynewcellarray=num2cell(oldmatrix) 来源: https://stackoverflow.com/questions/21336105/how-do-i-create-a-50x3-cell-array-from-a-50x3-matrix-keep-just-getting-a-1x1-ce

Accessing the contents of a 1x1 matlab cell

社会主义新天地 提交于 2019-12-02 01:46:13
问题 I'm not sure about the terminology, but I have read data from a text file into a 1x1 cell array P . When examining P , it lists "<142x2 cell>" in the (1,1) position. From there I can double-click this and it opens up into the 142x2 cell that I actually want. The issue is, I don't get how to manipulate this data via code to convert from the 1x1 cell array to the 142x2 cell array. Also, I cannot find anywhere what the curly brackets denote. 回答1: I don't get how to manipulate this data via code

Cell elements as comma separated input arguments for varargin function

自古美人都是妖i 提交于 2019-12-01 21:08:49
Imagine a function with a variable number of input arguments, alternately asking for a string and a value. myfunction('string1',value1,'string2',value2,...) e.g. myfunction('A',5,'B',10) I want to keep the ability to call the function like that and I dont want to change the evaluation of varargin inside the function. (Except ('string1','string2',...,value1,value2,...) if that helps) But I also have my input strings and values stored in a cell array inputvar <4x1 cell> : inputvar = 'A' [5] 'B' [10] Also this cell array has a variable length. My intention is to call my function somehow as