cell-array

Outputing cell array to CSV file ( MATLAB )

烂漫一生 提交于 2019-12-19 04:11:48
问题 I've created a m x n cell array using cell(m,n) , and filled each of the cells with arbitrary strings. How do I output the cell array as a CSV file, where each cell in the array is a cell in the CSV 'spreadsheet'. I've tried using cell2CSV , but I get errors ... Error in ==> cell2csv at 71 fprintf(datei, '%s', var); Caused by: Error using ==> dlmwrite at 114 The input cell array cannot be converted to a matrix. Any guidance will be well received :) 回答1: Here is a somewhat vectorized solution:

Calling function with varying number of parameters in Matlab

落花浮王杯 提交于 2019-12-18 13:36:05
问题 I am using symbolic toolbox to generate a matlab function. But the number of input to the generated function is varying with the number of objects that I need (e.g., number of switches). For 2 and 3 switches the generated function look likes this : y = fun(a1,a2,b1,b2) y = fun(a1,a2,a3,b1,b2,b3) In the script using this function I establish vectors of these parameters: a = [a1 a2 ...] What I want is to either call the generated function directly or make a wrapper function, so that I do not

Matlab Error: Function is not defined for 'cell' inputs

馋奶兔 提交于 2019-12-18 09:08:21
问题 fid = fopen('./tickers.tex', 'wt+'); for x = 1 : size(C.names,1) fprintf(fid, '%s & ', C.names(x,1:end-1)); fprintf(fid, '%s \\\\ \t\n', C.names(x,end)); end fclose(fid); Why does this give me the error: Error using fprintf Function is not defined for 'cell' inputs. While this does work: fprintf(' %f ', D{:}); I'm having difficulties understanding basic matlab datatypes. Could anyone provide me with a solution to print the cell array just like the last syntax? 回答1: Ok from the error and code

Create matrices from a given cell-array of strings with different lengths

流过昼夜 提交于 2019-12-18 07:23:32
问题 I have 3 sequences in a cell-array: Input_cell= {'ABCD','ACD', 'ABD'} S1= 'ABCD' % which means A<B<C<D S2= 'ACD' % which means A<C<D % missing B in the full string of 'ABCD' S3= 'ABD' % which means A<B<D % missing C in the full string of 'ABCD' I want to convert each of the strings in the Input_cell into a matrix M ( i -by- j ) which has to satisfy these conditions: M(i,j) and 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

Fastest way of finding repeated values in different cell arrays of different size

走远了吗. 提交于 2019-12-18 06:59:18
问题 The problem is the following: I have a cell array of the form indx{jj} where each jj is an array of 1xNjj , meaning they all have different size. In my case max(jj)==3 , but lets consider a general case for the shake of it. How would you find the value(s) repeated in all the jj i the fastest way? I can guess how to do it with several for loops, but is there a "one (three?) liner"? Simple example: indx{1}=[ 1 3 5 7 9]; indx{2}=[ 2 3 4 1]; indx{3}=[ 1 2 5 3 3 5 4]; ans=[1 3]; 回答1: Almost no

strsplit: undefined function for input type 'char'

*爱你&永不变心* 提交于 2019-12-18 03:16:23
问题 I have a <20x1> cell array and each of them stores some data in the form of a string (as it appears to me!!!). I want to access each element of the cell as an individual string and split is in words. The cell array I have is <20x1> cell array and to access each element as a cell I am using a for loop. for i=1:20 line=newline{i} end It shows me a all the elements within the array. Now since line is a string, I apply strsplit function to retrieve the words in the string. for i=1:20 words(i,:)

How can I create/process variables in a loop in MATLAB?

旧城冷巷雨未停 提交于 2019-12-17 16:52:24
问题 I need to calculate the mean, standard deviation, and other values for a number of variables and I was wondering how to use a loop to my advantage. I have 5 electrodes of data. So to calculate the mean of each I do this: mean_ch1 = mean(ch1); mean_ch2 = mean(ch2); mean_ch3 = mean(ch3); mean_ch4 = mean(ch4); mean_ch5 = mean(ch5); What I want is to be able to condense that code into a line or so. The code I tried does not work: for i = 1:5 mean_ch(i) = mean(ch(i)); end I know this code is wrong

Find index of all (non-unique) elements in a cell array as they appear in a second (sorted and unique) cell array

浪尽此生 提交于 2019-12-17 16:48:14
问题 A = {'A'; 'E'; 'A'; 'F'}; B = {'A';'B';'C';'D';'E'; 'F'}; I am trying to get for each string in cell array A , the index that matches that string in cell array B . A will have repeated values, B will not. find(ismember(B, A) == 1) outputs 1 5 6 but I want to get 1 5 1 6 preferably in a one liner. I can't use strcmp instead of ismember either as the vectors are different sizes. The vectors will actually contain date strings, and I need the index not a logical index matrix, I'm interested in

Generalization of mat2str to cell arrays

眉间皱痕 提交于 2019-12-17 16:46:08
问题 I sometimes miss a function to produce a string representation of a (possibly nested) cell array. It would be a generalization of mat2str, which only works for non-cell arrays (of numeric, char or logical type). Given an array x , how to obtain a string representation y , such that evaluating this string produces x ? For example, the input x = {[10 20], {'abc'; false; true;}}; should produce an output string like y = '{[10 20], {''abc''; false; true}}'; (or some variation regarding spacing an

How can I check whether an element is in a nested cell array?

让人想犯罪 __ 提交于 2019-12-14 02:43:55
问题 How can I check whether an element is in a nested cell array? ex: A = {{4 5 6};{6 7 8}}; b = 5; The function ismember(b,A{1}) does not work. Is there any solution better than for-loop? 回答1: Because each element is a cell, you don't have a choice but to use cellfun combined with ismember , which is the same as using a loop in any case. Your cells are specifically two-deep (per Andrew Janke). Each cell element in your cell array is another cell array of individual elements, so there is no