Answered
Substitute values in an array
If you do not know the indices in advance then you can use |diff| and |find|: >> d = [1,1,1,1,1,2,2,2,2,2,1,1,1,1,1]; >>...

11 years ago | 0

Answered
What is the syntax of fprintf
Why not read the documentation? <http://www.mathworks.com/help/matlab/ref/fprintf.html> And part way down the page is a ta...

11 years ago | 1

| accepted

Answered
Extracting square matrices from another matrix
% fake input data: t = 0.3; A = rand(7,273); % C = mat2cell(A,7,7*ones(1,39)); Z = expm(C{1}*t); for k = 2:3...

11 years ago | 1

| accepted

Answered
How to read txt file contain unstructured array
Try this: fid = fopen('temp.txt','rt'); C = textscan(fid,'%[^\n]','HeaderLines',3); fclose(fid); rgx = '^(\d+)\s+(...

11 years ago | 0

| accepted

Answered
how to seek and replace characters on cell
There is no need to use complicated |arrayfun|, simply use |A| as an index: >> A = [1 1 1;1 2 2;2 1 2;2 2 1]; >> map = {...

11 years ago | 0

Answered
How do I access and edit a cell array using a double for indexes?
<http://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-array.html *Cell Array Indexing*> Note that you canno...

11 years ago | 1

| accepted

Answered
How to divide matrix in submatrix
Here is some code that takes your matrix |a| (contained in the mat file |matlab|) and efficiently concatenates the location IDs ...

11 years ago | 1

| accepted

Answered
How to load data from other directory?
This is explained quite well in the documentation: http://www.mathworks.com/help/matlab/matlab_env/specify-file-names.html Und...

11 years ago | 5

Answered
How do I generate a vector of ordered integer without a loop or in faster way
You can adapt my answer to your <http://www.mathworks.com/matlabcentral/answers/257481-how-do-i-create-a-faster-ordered-vector-w...

11 years ago | 0

Answered
How do I create a faster ordered vector without for loop
X = floor(sqrt(0:(p+1)^2-1))'; This is nearly fifty times faster (p=1000): Elapsed time is 5.2233 seconds. Elapsed ...

11 years ago | 0

| accepted

Answered
Count pattern of a string
Count the substrings: >> S = '01234(01)3423(32)'; >> numel(regexp(S,'(\(\d+\)|\d)')) ans = 11 And check that it m...

11 years ago | 1

| accepted

Answered
Vector of dates going back one rolling year
You can subtract one from the year field: >> Vend = clock; >> Nend = datenum(Vend); >> Nbeg = datenum([Vend(1)-1,Vend...

11 years ago | 1

| accepted

Answered
Filling Cell Array with Empty value
As an alternative you can easily remove one level of the cell nesting: V = {{0;1;2};{3;4;5;6};{7;8;9}}; for k = numel(V)...

11 years ago | 0

Answered
Reading unformatted text and converting to formatted
You can read the whole file using <http://www.mathworks.com/help/matlab/ref/fileread.html |fileread|>, identify the digits using...

11 years ago | 0

| accepted

Answered
Finding the averages for a unique value.
This is *exactly* what the function <http://www.mathworks.com/help/matlab/ref/accumarray.html |accumarray|> is designed for! Use...

11 years ago | 0

Answered
How can I generalize it ?
Ugh... this is a really bad idea! Avoid creating dynamically named variables in MATLAB. This is poor practice as has been exp...

11 years ago | 0

Answered
creating a strucure from a string from my Tektronix MDO3034 oscilloscope
Using <http://www.mathworks.com/help/matlab/ref/textscan.html |textscan|> makes this task easy, and also allows us to use the |'...

11 years ago | 1

| accepted

Answered
summing over a multi-dimensional cartesian product using nested arrayfun commands
Maybe this can help: U = @(m,n)m+n; V = @(M,n)sum(arrayfun(@(m)U(m,n),M)); W = @(M,N)sum(arrayfun(@(n)V(M,n),N)); ...

11 years ago | 0

Answered
Why Do I get "Error using load Can't read file"?
That thread covers several different topics, and also advises that you should use |fullfile| (which your code does not) to provi...

11 years ago | 0

Answered
How to optimize a code to find postfix in a sting
Your first regular expression has a backslash, but your |sprint| version does not. The first regular expression: >> '\(?00....

11 years ago | 1

Answered
List of files sorting
You could download my FEX submission natsortfiles, which was written to deal with this exact problem: http://www.mathworks.com/...

11 years ago | 6

| accepted

Answered
speeding up a function
For a random vector of 10000 elements my code below is 30000 times faster than your code: Elapsed time is 27.6156 seconds. ...

11 years ago | 1

Answered
How i can reading character letter by letter
You can use |regexp|: >> X = regexp('123.56.128.117','\.','split') X = 123 56 128 117

11 years ago | 0

| accepted

Answered
I keep getting the error "Attempted to access counts(8,1); index must be a positive integer or logical." and I'm not sure why. I've looked through my code and it should work as far as I'm aware
*Better Solution* Why waste your time writing slow buggy code when you can simply use one of the inbuilt functions, such as <...

11 years ago | 1

Answered
varargout isn't working for output from GUI when same formatting works just fine in similar GUI
Perhaps the problem is really your |if| operator means that there are some instances where the callback is called but the |if| d...

11 years ago | 0

Answered
How to re-produce an existing variable in the script without using it?
It seems that you are looking for functionality like this FEX submission |uneval|: <http://de.mathworks.com/matlabcentral/fil...

11 years ago | 2

Answered
Creating an array of structs and using the field directly?
It is not clear why you need to structure at all, as the output is simply a cell array with some numeric scalars in it (Octave c...

11 years ago | 0

| accepted

Answered
gather data from different sections of each column
Preallocate the output before allocating to it: <http://www.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html> ...

11 years ago | 0

Answered
What does the expression x(ind -1) mean?
You are getting confused because you are mixing indexing with vector generation and you are not looking at the intermediate resu...

11 years ago | 2

Answered
How to fill values between two values.
You could use <http://www.mathworks.com/help/matlab/ref/interp1.html |interp1|>: >> A = [1,0,0,0,2,0,3,0,0,0,0,4,0,5]; >...

11 years ago | 0

| accepted

Load more