cell-array

Display cell array contents in another output format

天涯浪子 提交于 2019-12-11 03:42:41
问题 I am searching for a way display cell array contents other than with celldisp that gives me an output like the example below: celldisp(stuff) and a typical output: stuff{1} = 10 70 20 50 50 90 90 30 30 60 stuff{2} = 80 50 50 50 30 90 40 60 50 60 20 20 stuff{3} = 20 90 10 80 20 30 30 70 I would prefer to print it out like this instead: 10 70 20 50 50 90 90 30 30 60 80 50 50 50 30 90 40 60 50 60 20 20 20 90 10 80 20 30 30 70 Is this possible? Help is much appreciated! 回答1: One approach could be

Assign different values to cell arrays in MATLAB at once

大憨熊 提交于 2019-12-11 03:38:05
问题 I need help on creating a cell array in MATLAB where each cell is an array of different sizes. For example, let's assume I have this simple array and the value: A = [5 3 8 7 0 4 1]; B = 10; The cell array C must be created such that: C = [10 20 30 40 50] [10 20 30] [10 20 30 40 50 60 70 80] [10 20 30 40 50 60 70] [Empty matrix 1x0] [10 20 30 40] [10] Is it possible to do that in one operation only? I have tried: C = cellfun(@(a,b)b*ones(1,a), A,B) but it did not work. 回答1: cellfun expects a

Passing argument to cellfun matlab

佐手、 提交于 2019-12-11 02:28:37
问题 Hello I have a cell array of char (separated by underscore) that I would like to convert to double. I do it in a for loop, but since the dimensions are very big, it takes a lot of time. I would like to use cellfun , but I don't know how to pass the delimiter. Can you help me? listofwords = {'02_04_04_52';'02_24_34_02'}; for i = 1 : size(listofwords,1) listofwords_double(i,:) = str2double(strsplit(listofwords{i},'_'))./1000; end listofwords_double2= cellfun(@strsplit , listofwords); Benchmark

MATLAB: image corner coordinates & referncing to cell arrays

▼魔方 西西 提交于 2019-12-11 01:49:10
问题 I am having some problems comparing the elements in different cell arrays. The context of this problem is that I am using the bwboundaries function in MATLAB to trace the outline of an image. The image is of a structural cross section and I am trying to find if there is continuity throughout the section (i.e. there is only one outline produced by the bwboundaries command). Having done this and found where the is more than one section traced (i.e. it is not continuous), I have used the

Combine many cell arrays into one cell array (Matlab)

强颜欢笑 提交于 2019-12-10 22:27:12
问题 I have 3 cell arrays : c1={'a','b','c'} c2={'a2','b2','c2'} c3={'a3','b3','c3'} How can I combine those 3 cell arrays into 1 cell array C as follows: C={'a','b','c','a2','b2','c2','a3','b3','c3'} 回答1: You can simply use square brackets; c = [c1, c2, c3] % c = {'a' 'b' 'c' 'a2' 'b2' 'c2' 'a3' 'b3' 'c3'} This can be used when appending items to the end of a cell too, d1 = {'a', 'b', 'c', 'd'}; d2 = [d1, {'e'}]; 回答2: With colon you can create comma separated lists and then concatenate them: c =

In MATLAB how do I insert a string at beginning of of each string in a cell array?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 15:19:11
问题 I have a cell array of numeric strings e.g.: labels = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'} I'm trying to add a string ( 'Label ' ) to the beginning of each array element without using any kind of loop, as the array is massive and I need the code to run quickly. My other requirement is the space after the word 'Label' must be maintained once I apply it to the two-digit elements in the array. The result I want is: fullLabels = {'Label 1', 'Label 2', 'Label 3', 'Label

Access predefined elements of cells

冷暖自知 提交于 2019-12-10 10:57:45
问题 I have a cell array A [1x80] in which each element is a cell array itself [9x2]. I have also a vector B representing a group of selected cells of A and I want to extract the element {2,2} of each selected cell. I tried with a simple A(1,B){2,2} but of course it doesn't work.... Can you help me? 回答1: How about this: A = {{1 2; 3 4}, {5 6;7 8}, {9 0; 1 2}; {3 4; 5 6}, {7 8; 9 0}, {11 22; 33 44}}; B = [2,3] [cellfun(@(x)x(2,2), A){1, B}] ans = 8 2 EDIT: The above actually only works in octave.

How to create cell-array in MATLAB and initialize all elements to the same object?

南笙酒味 提交于 2019-12-10 02:09:38
问题 I have a matrix (call it X ) that is initialized to say zero(3) . I want to change the code so that X is a cell array of size (say) (3,1) and initialize each element to zero(3) . I can do it with a loop but is there a better way? X = cell(3,1); for ii=1:numel(X) X{ii} = zeros(3); end 回答1: You can do this with deal() . >> [X{1:3, 1}] = deal(zeros(3)) X = [3x3 double] [3x3 double] [3x3 double] 回答2: An alternative way: X = repmat({zeros(3)}, 3, 1); another one: X = cell(3,1); X(:) = {zeros(3)};

MATLAB Cell Array - Average two values if another column matches

妖精的绣舞 提交于 2019-12-08 11:00:18
问题 I have a cell array in which some of the entries have two data points. I want to average the two data points if the data were collected on the same day. The first column of cell array 'site' is the date. The fourth column is the data concentration. I want to average the fourth column if the data comes from the same day. For example, if my cell array looks like this: 01/01/2011 36-061-0069 1 10.4 01/01/2011 36-061-0069 2 10.1 01/04/2011 36-061-0069 1 7.9 01/05/2011 36-061-0069 1 13 I want to

Change the format of a cell array Matlab

蹲街弑〆低调 提交于 2019-12-08 04:40:50
问题 I have a A which is 640x1 cell, where the value of each cell A(i,1) varies from row to row, for example: A(1,1)=[] A(2,1)=[1] A(3,1)=[1,2,3] What I want to do is to convert A to be like this: A(1,1)=[] A(2,1)=1 A(3,1)=1; A(3,2)=2; A(3,3)=3 so that each cell has only one value. So if anyone could assist me how can I do this? This is a part of who A looks like A= [] 0 0 0 145 [144;192] [145;197;307] 回答1: Example: % first lets create some random cellarray containing data of different length A =