Take average of multiple matrices
Try this %% load('data.mat') num = cat( 3, phi_BFD_v_sum{:} ); avg = mean( num, 3 ); peek >> avg avg = 0 ...

1 year ago | 1

Pre-allocating cell containers
"I have pre-allocated memory". After pre-allocating memory for a variable you must not change its size. If you do, the effect o...

1 year ago | 0

how to save the outputs obtained by a for loop repeated n times
tot is overwritten in each iteration of the for-loop Replace tot = (Tin{idx(:,i),i+1:i+3}); by tot(:,i) = (Tin{idx(:,i),i+...

1 year ago | 0

| accepted

Kill a system process if it takes too long
I did this long time ago and have forgotten the details. And I haven't access to my code now. Thus from the top of my head. Ther...

1 year ago | 1

Counting in one column that is conditional on another column
Does this do what you look for? %% limits = { [0;4], [4;5], [5;6], [6;7], [7;inf] }; %% some simple test data trials = {[ ...

1 year ago | 0

| accepted

How to change data in a cell array of doubles?
??? "doing time = time - 1" doesn't "fix the time so that it starts from 0" Try this >> load('trials.mat') >> cac = cellf...

1 year ago | 1

| accepted

Fprintf not inserting new line correctly with /n
The documentation of fprinf says fprintf(formatSpec,A1,...,An) applies the formatSpec to all elements of arrays A1,...An i...

1 year ago | 1

| accepted

convert string to equation
Or a smelling solution if you don't have the symbolic toolbox >> x=3; >> v = eval('(5*x^2)') v = 45 >> Create an ano...

1 year ago | 0

Find the value at exact location in a text file
An alternative construct based on ismembertol(). I believe it's faster. %% fid = fopen( 'cssm.txt', 'rt' ); % cssm.txt conta...

1 year ago | 0

MATLAB not displaying answer correctly in command window
Look up the help on format specifier of fprintf(). Next replace the spec, %s, in your %%Display section by %+7.2f The tripl...

1 year ago | 0

| accepted

Convert imported data from table to array
See table2array - Convert table to homogeneous array

1 year ago | 0

| accepted

Help placing user input into an element in a row vector
Look up for in the documentation ... replace for i = 1 < score by for i = 1 : data

1 year ago | 0

Putting three separate arrays into one new array
Try NewArray = [array1, array2, array3]; or NewArray = horzcat(array1, array2, array3); instead

1 year ago | 1

| accepted

2 columns put together
One way >> c = [x,y]; % concatenate x and y horisontally >> c(2,:) % second row ans = 0.585 0.4926 >>...

1 year ago | 0

How to extract certain values from an array
First see Array Indexing and Find Array Elements That Meet a Condition. Then try >> x=[8,5,5,5,9,4,3,2,9,10]; >> new = x(x<7) ...

1 year ago | 0

| accepted

How can I change an element in a matrix with the median of itself and its surrounding elements.
"but I do not know how to specify the median function to take the localized 3x3 matrix of a larger array" Combine these two e...

1 year ago | 0

How do you import specific rows of numeric data (without text) for the file I have attached?
Maybe not the most rubust way, but it does the job. (The numerical blocks must be followed by non-numerical text.) %% ffs = '1...

1 year ago | 0

| accepted

How to Speedup conditional vector elements replacement?
There is a Matlab function, repelem, that does it. >> repelem( b, a ) ans = Columns 1 through 13 1 6 6 6 ...

1 year ago | 0

| accepted

Create all combination of strings
See: perms, All possible permutations In response to comment Does the function, cssm(), do what you ask for? >> all_permuta...

1 year ago | 0

Question

How to edit and replace comments on File Exchange submissions?
It's a hidden algorithm that controls what happens when I write comments on my submissions at File Exchange. I failed to find a ...

1 year ago | 0 answers | 0

### 0

Speed up code:: Code is working but slow..
See: Profile Your Code to Improve Performance and Techniques to Improve Performance

1 year ago | 0

How do I use numerical and logical indices to get this output?
One out of many ways %% myArray = [2, 4, -3, 6, 9]; isneg = myArray < 0; myArray( isneg ) = 1;

1 year ago | 1

Change [ ] cells in .mat file to NaN
I don't fully understand your question. See: TUTORIAL: how to ask a question (on Answers) and get a fast answer "The code bel...

1 year ago | 0

How do I append a row average to a new matrix
With a little bit of guessing. Does this answer your question? %% foo = randi(500,500); cac = mat2cell( foo, 5*ones(100,1), 5...

1 year ago | 1

| accepted

Preventing too many function inputs
>> exfunction(1,3,9,4,5) throws the error Error using exfunction Too many input arguments. I assume that's the error you e...

1 year ago | 0

MATLAB Answers Wish-list #5 (and bug reports)
Activity Feed: "See more" asks for "See less".

1 year ago | 1

How to modify few numbers in a random text file?
Try this %% chr = fileread('model_v2.txt'); ffs = 'model_out.txt'; fid = fopen( ffs, 'w' ); [~] = fprintf( fid, chr, 1.2, 3...

1 year ago | 0

| accepted

How to replace elements of a cell array using a containers.Map
With string and arrayfun on R2018b %% names_to_replace = ["TonnageDeBSA", "D__bitD___eauAuBSA", ... "Pres...

1 year ago | 0