If you'd like, you can use the two data types to create a table in MatLab. I'm not terribly familiar with its use, but it seems to be well documented. I'm sure someone else can expand upon this. Edit: After re-reading your question, I think this is closer to what...

Just choose the ones that have more than 4 elements by logical indexing: result = result(cellfun('length', result) >= 5); ...

One approach - out = cellfun(@(x) iscell(getfield(A,x)),A.Properties.VariableNames) Or, a better way would be to access the fields(variables) dynamically like so - out = cellfun(@(x) iscell(A.(x)), A.Properties.VariableNames) Sample runs: Run #1 - A=table([1;2;3],{4;5;6}) A = Var1 Var2 ____ ____ 1 [4] 2 [5] 3 [6] out = 0 1 Run #2...

Another method I can suggest is to operate on each column separately. We could use logical operators on each column to search for cards in your cell array that contain a specific number in the first column, followed by a specific suit in the second column. To denote a match,...

arrays,matlab,matrix,cell-array

i) No, not really. You need to put [10, 3, 4] into a variable a and then get the second element a(2). (You can do it, but it's not worth it). ii) Yes: just use funcs{2}(2), or feval(funcs{2}, 2). iii) You can try something like: >> inarg = 1; >>...

arrays,matlab,matrix,cell-array

You can use the powerful accumarray function for this task: [uniqueCol1, ~, u1] = unique(myBigMatrix(:,1)); [uniqueCol2, ~, u2] = unique(myBigMatrix(:,2)); R = accumarray([u1 u2], (1:size(myBigMatrix,1)).', [], @(x) {myBigMatrix(sort(x),:)}) Then R{m,n} contains the submatrix that matches the m-th element of uniqueCol1 and the n-th element of uniqueCol2. Example: myBigMatrix = 3...

string,matlab,text-processing,cell-array

Case 1: Consistent sizes %%// Input (different from question for a better demo) Cell_in = {'airplane1','bat1','ball3','cat3','coal1','doggie3'}; ids = cellfun(@(x) x(end), Cell_in,'uni',0) [~,ind] = sort(ids) Cell_out = reshape(Cell_in(ind),[],numel(unique(ids)))' %%// Output Output Cell_out = 'airplane1' 'bat1' 'coal1' 'ball3' 'cat3' 'doggie3' Case 2: Inconsistent sizes Cell_in = {'airplane1','bat1','ball3','cat3','coal1','doggie3','cat2','ball2'}; ids = cellfun(@(x) x(end), Cell_in,'uni',0)...

arrays,string,matlab,cell-array

Just use str2num(A{n}) to convert each cell of A back into numeric form: R = A(arrayfun(@(n) any(ismember(B,str2num(A{n}))),1:numel(A))); The above gives the result in string form, because A{n} is converted to numbers within ismember but A is left in string form. If you want the result in numeric form, first convert...

You have a double-nested cell array: Q = { {[0] [1] [0] [238]} } and you need comma-separated lists to transform it into an array. I assume you have multiple cell arrays within Q, so you can use cellfun: out = cellfun(@(x) [x{:}], Q,'uni',0) and you get Q{1} = [0]...

You can use matfile with cells as long as you are not trying to index into the actual cells. Remember that cells are still arrays, so you can access each cell using array indexing. For example: >> x = {'this', 'is', 'an', 'example'}; >> x{4} ans = example >> x(4)...

matlab,vectorization,cell-array

For your example, you could do the following using the cellfun function: fcnList = {@(x) (x+1), @(x) (x+2)}; a = 2; cellfun(@(func) func(a),fcnList) ans = 3 4 Where I have created a handle called func which accepts as input a function from the fcnList variable. Each function is then evaluated...

arrays,matlab,matrix,cell-array

Some possibilities: Use cellfun with isequal to test each element of B for equality: find(cellfun(@(x) isequal(x,A), B)) If all matrices have the same size: concatenate into a 3D array (or better yet, use a 3D array from the beginning), and use bsxfun for the comparison: find(all(all(bsxfun(@eq, A, cat(3, B{:})),1),2)) ...

Two methods to do this are containers.Map and logical indexing Logical indexing firstly we will find the occurance of the input in the first column with strcmp using ind=strcmp(pippo(:,1),'nimp') and then get the contents of the cell in the second column where this is true pippo{ind,2} which can be combined...

arrays,string,matlab,cell-array

headers = {'header1', 'header2', 'header4'}; for n = 1:length(names) headerstring = names{:,n}; [temp, N] = max(strcmp(headerstring, headers)); % // N now contains which in the list of 'headers', 'headerstring' matches. % // strcmp(string, stringcellarray) returns a vector of 0s and 1s ... % // ... corresponding to if string equals...

A couple of things to try, it depends how well you know your data. str2double at it's core uses sscanf but does a lot of checking. If your data is good then for step 1 create an anonymous function to do the replacement and conversion in one step using sscanf...

You don't need the curly brackets around whatever you're assigning into a cell. The assignment is exactly symmetric to reading out the value: s = sentiment{i}; sentiment{i} = s(15:22); Surrounding a value with {} actually creates a cell array, which is why you appear to have a subcell. To help...

matlab,text-processing,cell-array

Let data.txt contains 16 54 1 -3 5 15 5 1 9 10 5 You can read it into a cell array data with the following: fid = fopen('datatest.txt'); allData = textscan(fid,'%s','Delimiter','\n'); data = cellfun(@str2num, allData{1}, 'UniformOutput', false); fclose(fid); >> data = ans = [1x5 double] [1x2 double] [1x4 double]...

For a 1D cell array - first_vals = arrayfun(@(n) data{n}(1),1:numel(data)) This should work for a general case - first_vals = reshape(arrayfun(@(n) data{n}(1),1:numel(data)),size(data)) ...

That's because you forgot to inherit from the handle class: classdef sampleClass < handle %// Change here! properties list = {} end methods function addToList(obj) obj.list{end+1}='test'; obj.list end end end If you want to retain the changes made when modifying an instance of your class, you must inherit from the...

matlab,indexing,data-structures,octave,cell-array

The problem is that when you get to the for loop that is causing a problem, data already exists and is a struct array. octave> data data = 8x1 struct array containing the fields: name date bytes isdir datenum statinfo When you select a field from a struct array you...

arrays,matlab,nested,cell,cell-array

You'd better use a matrix (as suggested by Divakar): M = reshape(cell2mat([A{:}]),[],numel(A)).'; Or more simply, as noted by knedlsepp: M = cell2mat(cat(1,A{:})); Then your desired "variables" are the rows of M, that is, M(1,:), M(2,:) etc....

regex,matlab,multiple-columns,cell-array

You can do it by concatenating the data between 1x9 cells by using a combination of vertcat and {:}. %//First form T str='1,26:00:01.490, 2.40,101.2, 7.8,-24.0,20.40,-0.76,-0.26'; str=repmat({str},20,1); Data=regexp(str,',','split'); Data1=vertcat(Data{:}); %//Get your time data in form of cells timeData_cells=Data1(:,2); %//Get your time data in form of a matrix timeData_matrix=vertcat(Data1{:,2}) %//This will work...

As the other answer mentions, you need to use nonzeros but even if you do that, the order of the output wont be preserved. Instead, you could Try this: out = cellfun(@(x) x(any(x,2),:),C,'UniformOutput',false); Display the cell array using celldisp celldisp(out); ...

Input A of class cell and input B of class char must be cell arrays of strings, unless one is a string. This means that every entry in the cell must be a string, and in this case it's not. If your cell array contains numeric values, or even...

This can be done with a combination of reshape and permute. This approach works for numeric arrays or for cell arrays. Let A denote your array. Then, the desired result is B = reshape(permute(reshape(A.',N,M,[]),[2 1 3]),M,[]); Or, as noted by Divakar, you can save the transpose, which will reduce running...

If you want to make dynamic field names in structures, I don't see how else you can do it without two for loops. Let's say we have two cell arrays A and B that consist of string entries. For my example, apologies for the strings inside these arrays in advance...

Straight-forward Approaches With arrayfun - out = find(arrayfun(@(n) any(strcmp(C{n},'hello')),1:numel(C))) With cellfun - out = find(cellfun(@(x) any(strcmp(x,'hello')),C)) Alternative Approach You can adopt a new approach that translates the input of cell array of cell arrays of strings to cell array of strings, thus reducing one level "cell hierarchy". Then, it performs...

matlab,cell-array,n-dimensional

This is also a mess, but works. It goes the ND-array way. X = [1 1 1 0.64 1 2 1 0.86 1 1 1 0.74 1 1 2 0.56]; %// data N = size(X,1); %// number of values [~, ~, label] = unique(X(:,1:end-1),'rows'); %// unique labels for indices cumLabel...

use : cellfun(@unique,input,'UniformOutput',0) ans = 'CEGH' 'CEG' 'ABCDEF' 'BCFG' 'BCDEG' 'BEFH' 'ACEGH' EDIT: To conserve ordering in case the letters are not sorted, as @thewaywewalk commented, you can use: cellfun(@(x) unique(x,'stable'),input,'UniformOutput',0) ...

As already mentioned a lot depends on the data, but in your example the fastest way is probably a nested for loop: A={ [2 3;4 5] [1 5;7 8]}; B={ [1 2;4 5] [7 9;10 1]}; tic C=cellfun(@minus,A,B,'UniformOutput',false); toc tic s = size(A); for ii=1:s(1) for jj=1:s(2) D{ii,jj} = A{ii,jj}-B{ii,jj};...

arrays,string,matlab,cell-array

Use curly braces to refer to the contents of a cell: data{1} = 'hello'; %// assign a string as contents of the cell The notation data(1) refers to the cell itself, not to its contents. So you could also use (but it's unnecessarily cumbersome here): data(1) = {'hello'}; %// assign...

arrays,matlab,cell-array,multidimensional-array

One way to achieve that would be - vertcat(cell_array1{:}) ...

That should do it: Responses = {[1 3 2 6 4] [4 2 5]} sizeLongest = max(cellfun(@numel, Responses)); Responses = cellfun(@(x) [x x(randi(numel(x), 1, sizeLongest - numel(x)))], Responses, 'UniformOutput', false); First, it takes the size of the longest sequence. Then, it uses cellfun and, for each array x, it concatenates...

Assuming A to be the input cell array, there could be two approaches here. Approach #1 %// Initlialize output array Aout = cell(size(A)); for k = 1:size(A,2) %// Select one column Ak = A(:,k); %// Logical array with size of Ak and ones at places with non-empty strings pos =...

matlab,matrix,indexing,cell,cell-array

Based on what I have understood, I think this would work for you and should be more efficient too - %// Get matches between each element of col1 of RF against each in its col2 RF12 = bsxfun(@eq,RF(:,1),RF(:,2)'); %//' %// Cut each cell of M into cells that have only...

How about this: cellfun(@(x) nansum(x,ndims(x)+1), raw_data, 'UniformOutput', false) Note if you're certain you'll only have 2D matrices in raw_data you can replace the ndims(x)+1 with 3. The idea is to use nansum to sum along the 3rd dimension as this will preserve the shape of the first 2 dimensions and...

Why not use a cell-Array for these kind of problem? How did you generate your C matrix? Even though you have used cell-Arrays for C matrix, each element of C is a matrix in your case, so that the dimensions should be constant. I have used a cell array inside...

regex,string,matlab,text-processing,cell-array

You can make use of strsplit and/or regexp to get the row,col elements in individual cells: >> strsplit(str,'\\n') ans = 'var1,var2' 'var1,var2,var3' ',var9' ',var12,var13,var14,v15' >> tab = regexp(strsplit(str,'\\n'),',','split'); >> tab{:} ans = 'var1' 'var2' ans = 'var1' 'var2' 'var3' ans = '' 'var9' ans = '' 'var12' 'var13' 'var14' 'v15'...

You can let MATLAB expand the cell array when needed: F={}; for k = 1:numel(D), F(1:numel(D{k}), end+1)=D{k}; end which results in F = 'abc' 'baa' 'acc' 'acd' 'bbb' 'aaa' 'aaa' [] 'aad' If it is important to have empty matrices as empty strings, use >> F(cellfun('isempty', F))={''} F = 'abc'...

arrays,matlab,matrix,cell-array

It's high time you get into bsxfun! Here's the implementation - %// Get the number of elements in each column of the input cell array lens = sum(cellfun('length',reshape(a,[],size(a,3))),1) %// Store the maximum number of elements possible in any column of output array max_lens = max(lens) %// Setup output array, with...

matlab,matrix,indexing,cell-array

end simply stand for the size of the variable at the corresponding dimension whatIsEnd = size( a{1}, 2 ); %// size along second dim Therefore, end+1 is whatIsEnd+1. If cell-array a has many elements and you wish to know the end of each and every one of them, you may...

arrays,matlab,matrix,vectorization,cell-array

The action you want to perform requires an assignment within a function. The only way to achieve this is using eval, which is considered bad practice. A loop is therefore the best remaining option, if you want to keep everything in one script: A = {randn(2,3),randn(2,3)}; for ii = 1:numel(A)...

matlab,cell,simulink,cell-array,matlab-coder

Please read through the MATLAB Code Generation Manual. There, in the General Limitations section, it clearly states that You cannot use cell arrays in your code. The solution to this is presented in the MATLAB Central: You have to replace the cell arrays by e.g. structs. As I see from...

arrays,matlab,matrix,duplicate-removal,cell-array

In this case it's hard to avoid loops. You can go along the following lines: ind = true(1,numel(TILER)); %// true indicates non-duplicate. Initiallization for ii = 1:numel(TILER)-1 for jj = ii+1:numel(TILER) if isequal(TILER{ii}, TILER{jj}) ind(jj) = false; %// mark as duplicate end end end TILER2 = TILER(ind); Some optimizations are...

matlab,grouping,average,cell-array

With a combination of unique and accumarray you can achieve what you want. %// example data times = { 'plot' 'plot' 'plot' 'plot' 'hist' 'plot'; [1] [2] [3] [4] [5] [6] } %// extract data data = [times{2,:}] %// get types and their locations [types, ~, subs] = unique(times(1,:)) %//...

A couple of ways that I figured you could go: % First define the MSE function mse = @(x,y) sum(sum((x-y).^2))./numel(x); I'm a big fan of using bsxfun for things like this, but unfortunately it doesn't operate on cell arrays. So, I borrowed the singleton expansion form of the answer from...

What I suspect you are doing is something like this: B = A(v, c); When you specify vectors to index into A, it finds the intersection of coordinates and gives you those elements. As such, with your indexing you are basically returning all of the elements in A. If you...

Here's a vectorized solution: desired = strcat(num2str([plant_tag{:,1}].'), '_', plant_tag(:,2)); ...

arrays,string,matlab,cell-array

I'm assuming your input is input = {[546] 'Blah blah blah' [783] 'Magic string' [1341] 'Blah, blah, other stuff' [1455] 'Magic string' [1544] 'Another irrelevant string' [1700] 'Yet another pointless string' [1890] 'Magic string'} that is, the strings are directly in the cell array, not in second-level (nested) 1x1 cell...

This is another classic case of accumarray. accumarray works by using a bunch of keys and a bunch of values. For those keys that are the same, the corresponding values get mapped to the same bin and the default behaviour of accumarray is to add up those values that get...

arrays,string,matlab,file-io,cell-array

importdata does that for you: >> x = importdata('file.txt'); x = 'ABCCD' 'HGAQ' 'VBSER' >> whos x Name Size Bytes Class Attributes x 3x1 364 cell ...

you could use fliplr, but it operates on each index of the cell instead of the whole cell. To wrap it all in one line, use cellfun recelldata = cellfun(@(x) fliplr(x), celldata,'UniformOutput', false) >>'BA' 'EB' 'CB' ...

Approach #1 %// Inputs A= {'paul',5 ,'sean' ,5,'rose', 1,'jim',4} B= {'jim', 'paul', 'george', 'bill', 'sean' ,'rose'} %// Reshape A to extract the names and the numerals separately later on Ar = reshape(A,2,[]); %// Account for unsorted A with respect to B [sAr,idx] = sort(Ar(1,:)) Ar = [sAr ; Ar(2,idx)] %//...

I take that n1(i,1) is always a row vector so you should use, n1{i,1}(j) = []; If n1(i,1) is not a column or row then removing an element from middle would be impossible. for example: A = {[1 2 3],[5 8 9]} A{1,2}(1,2) = [] gives the error: A null...

Try num2cell: myStructCell = num2cell(myStruct); For example: >> myStruct(1).name = 'John'; >> myStruct(2).name = 'Paul'; >> myStruct myStruct = 1x2 struct array with fields: name >> myStructCell = num2cell(myStruct) myStructCell = [1x1 struct] [1x1 struct] >> myStructCell{1} ans = name: 'John' >> myStructCell{2} ans = name: 'Paul' >> myStructCell{2}.name ans...

matlab,matrix,vectorization,cell-array

Vectorize it like this, for a given cell of raweeg: startpoints = raweeg{1,1}(raweeg{1,1}(:,2) ~= -1, 1); This is called logical indexing. Just be sure your markers are not generated with floating point computations, or the comparisons will likely fail often. P.S. The problem in your code is the for loop...

The answer provided by Matt correctly shows the issue with your code. However, you can use strcmp directly because it accepts two cell array of strings as input >> strcmp(names(1:end-1), names(2:end)) ans = Columns 1 through 14 1 1 1 1 1 1 1 1 1 0 1 1 1...

If you mean adding a single cell to the end (i.e. so you 1-by-3256 cell array becomes a 1-by-3257 cell array) then: Q{end+1} = [] and you can replace [] with your value directly Alternately: Q(end+1) = {[]} ...

Take the first value input = Q(1); % or Q{1} depending on requirements Clear the first value: Q(1) = []; % Q will now be, e.g. 1x3255 cell % Q(1) is now the old Q(2) This needs to be () not {} - the latter will empty the contents of...

Perfect setup for bsxfun's masking capability here! Now, I am assuming your data is setup as described in your previous question - To solve the case of filling up "empty spaces" with zeros, you can setup an output array with maximum possible number of elements in each column and then...

matlab,indexing,analytics,cell-array

You were missing the definition of indices of the columns: A = rand(10,2) C = {A,A,A,A,A}; %// here ....| D = cellfun(@(x) x(1:5,:), C,'UniformOutput',false) In this case you want all columns, that's why you use :. You could also use x(1:5,1:2) - in your case it's equal to x(1:5,:). C...

Something like this might meet the needs - %// Input outstr ={ 'a' 'b' 'Fa' 'Fb' 'Xn' 'Fx' 'sign Fa*Fx' '0.70000' '0.90000' '-0.19592' '0.33887' '0.77327' '0.02896' '-' '0.70000' '0.77327' '-0.19592' '0.02896' '0.76383' '0.00206' '-' '0.70000' '0.76383' '-0.19592' '0.00206' '0.76316' '0.00012' '-' '0.70000' '0.76316' '-0.19592' '0.00012' '0.76312' '0.00000' '-' } outstr1...

I'm assuming that by "element" you mean the whole vector. So for example, given Q = {[1 2 3], [4 5]} the new vector [2 4 3] should be added, but [4 5] should not. To do that check: denoting the new vector by new, use alreadyExists = any(cellfun(@(x) isequal(x,...

matlab,function,cell,cell-array

Convert the nested cell array into a 2Dmatrix first by using the following code A = reshape(cell2mat([y2a{:}]),[],numel(y2a)).'; You could as well look at the below link for i too had asked a similar thing How to separate data from nested cells? Then perform the required action using B=num2cell(A);%convert it into...

With that structure, A is uniquely determined by the number of elements of each of its cells, and the result can be obtained as C = sum(bsxfun(@gt, B, cumsum(cellfun(@numel, A))), 2)+1; ...

Approaches With arrayfun and ismember - Result = A(arrayfun(@(n) any(ismember(B,A{n})),1:numel(A))) Or with arrayfun and bsxfun - Result = A(arrayfun(@(n) any(any(bsxfun(@eq,B(:),A{n}),2)),1:numel(A))) Or with arrayfun and setdiff - Result = A(arrayfun(@(n) numel(setdiff(B,A{n})) < numel(B),1:numel(A))) Or with arrayfun and intersect - Result = A(arrayfun(@(n) ~isempty(intersect(B,A{n})),1:numel(A))) One could also use cellfun here, such that...

arrays,string,matlab,cell-array,textscan

For your problem, cell2mat is the wrong function. Consider the cell array of strings: >> S = {'1.2';'3.14159';'2.718'} S = '1.2' '3.14159' '2.718' >> cell2mat(S) Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 83) m{n} = cat(1,c{:,n}); That's because each row of the...

You can store it in a 3 dimensional array: A = rand(3,4,3); Access the i-th layer with: A(:,:,i) ...

matlab,search,matrix,cell-array

Here is a solution. Given a m x 1 column cell array C of matrices, this code deletes the equivalent duplicates. (Here it will delete the 4th and 5th matrices, which are equivalent to the 1st). C{1} = magic(3); C{2} = magic(4); C{3} = magic(5); C{4} = C{1}; C{5} =...

You can use importdata. This gives each line in a different cell. You then split each line using regexp with the 'split' option: y = importdata('filename.txt'); y = regexp(y, ',', 'split'); %// or ', ' y = cat(1, y{:}); ...

Accumarray accepts functions both anonymous as well as built-in functions. It uses sum function as default. But you could change this to any in-built or anonymous functions like this: In this case you could use max function. in = horzcat(a,b).'; [uVal,~,idx] = unique(in(:,1)); out = [uVal,accumarray(idx,in(:,2),[],@max)].' ...

I think this does what you want. I've denoted your cell array as c. n1 = find(cellfun('isempty',c(1,:)), 1); %// first empty cell in row 1 n2 = find(cellfun('isempty',c(2,:)), 1); %// first empty cell in row 2 c(1,n1:n1+n2-2) = c(2,1:n2-1); %// copy the relevant part of row 2 onto row 1...

matlab,cell-array,function-handle

As constructed, the *fun family of functions exists for this purpose (e.g., cellfun is the pertinent one here). They are other questions on the use and performance of these functions. However, if you construct f as a function that constructs a cell array as f = @(x) {sin(x), cos(x), x+4};...

matlab,if-statement,vector,cell,cell-array

Use == for comparison and = for assignment. So if fs{i,j}==00, etc. Edit: Matlab is really designed for highly vectorized operations. Nested loops are slow compared to native functions, and typically can be replaced with vectorized versions. Is there any particular reason why you are using cell arrays instead of...

Using cellfun, strfind and str2double out = cellfun(@(x) str2double(x(strfind(x,'_')+1:strfind(x,'.')-1)),A) How does it work? This code simply finds the index of character one number after the occurrence of '_'. Lets call it as start_index. Then finds the character one number lesser than the index of occurrence of '.' character. Lets call...

matlab,uitableview,matlab-guide,cell-array,clickable

Short answer: you can't MATLAB GUI only provides only a very parse set of possible gui-elements check this documentation of MATLAB GUI. You need to change your request, so e.g. create an uitable or something like this. If you desire to create more advanced stuff in MATLAB GUI's, then you...

You need to call cellfun twice, once on lists and once on its elements cellfun(@(x) x(~cellfun('isempty', x)), lists, 'uni', 0) ...

arrays,matlab,cell,zero,cell-array

Assume that your cell array is stored in the variable c. First, we can determine which of the rows of element 5 are not equal to 0 using a logical operation: notZeros = (c{5} ~= 0); Then, loop through the elements and apply the logical index to filter out the...

arrays,matlab,indexing,cell,cell-array

See if this approach works for you - sz = cell2mat(cellfun(@size,C1(1),'uni',0)) row1 = sz(1); col1 = sz(2); t1 = reshape(horzcat(C1{:}),row1,col1,[]) t2 = reshape(horzcat(C2{:}),row1,col1,[]) b1 = t1==C1_value b2 = t2==C2_value tt1 = reshape(b1,row1*col1,[])' %//' tt2 = reshape(b2,row1*col1,[])' %//' tt22 = permute(tt2,[3 2 1]) tt3 = bsxfun(@and,tt1,tt22) [C1_cellnum,subcellnum,C2_cellnum] = ind2sub(size(tt3),find(tt3)) %// outputs...

I used this pice of code to generate data: %generating some dummy data m=1000; s=100; t=100; cell_in=cell(m,1); for idx=1:m cell_in{idx}=cell(randi(s),randi(t)); end Applying some minor modifications, I was able to speed up the code by a factor of 5 %Minor modifications of the original code %use arrays instead of cells for...

Here is some simple parsing routine that returns directly elements and connections as cell vectors. NB: Parsing assumes text file is well formatted and is always elements, followed by connections. function [elements, connections] = ReadElementsAndConnections(filename) %[ % For debug if (nargin < 1), filename = 'ElementsAndConnections.txt'; end % Read full...

The problem is that datenum quits with an error as soon as it finds a non-conforming string. So it's difficult to do it in a vectorized manner in your case (see Divakar's answer, tough). Here's a quick and dirty solution with try and a for loop: First define the data:...

Use logical indexing and compare first and second column: out = pairs(pairs(:,1)~=pairs(:,2),:) For a more general way (to cover rows with more than two characters) you can create the index of rows that have all elements equal to each other using bsxfun: allsame = any(~bsxfun(@eq, pairs, pairs(:,1)), 2); out =...

arrays,string,matlab,printf,cell-array

If you type help fprintf it says: fprintf - Write data to text file But you want help sprintf: sprintf - Format data into string So you can fix your problem using: C.labels = cellfun(@(x,y) sprintf('%s-%s',x,y), A.labels, B, 'uni',0) This uses: cellfun to take corresponding pairs of A.labels and B...

arrays,matlab,structure,cell-array

%get the right order using second output of sort [~,index]=sort({oo.Item}) %sort it oo=oo(index) ...

arrays,matlab,string-matching,cell-array

I believe the following codes must take care of both of your tasks - [x1,x2] = ismember(totalSalesCell(:,1),weeklySalesCell(:,1)) corr_c2 = nonzeros(x1.*x2) newval = cell2mat(totalSalesCell(x1,2)) + cell2mat(weeklySalesCell(corr_c2,2)) totalSalesCell(x1,2) = num2cell(newval) excl_c2 = ~ismember(weeklySalesCell(:,1),totalSalesCell(:,1)) out = vertcat(totalSalesCell,weeklySalesCell(excl_c2,:)) %// desired output Output - out = '23DFG' [ 5] 'DGH8444' [ 9] '12345' [10] 'PLM78'...