Answered
What's the best way to add semi-colons after each element of a matrix?
>> D = regexprep(C,'\S+','$&,'); >> D{:} ans = 0, 0, 0.1, 0.0016892, 0.2, 0.0068476, 0.3...

8 years ago | 1

| accepted

Answered
How to arrange data with scirpt ?
Swapping is simple with indexing: >> a = 1:10 a = 1 2 3 4 5 6 7 8 9 10 >> L = [1,2,3...

8 years ago | 1

| accepted

Answered
how do i have a structure into a variable when the structure was created in a for loop?
You need to allocate the function output to a variable. It does not have to have the same name as the variable _inside_ the func...

8 years ago | 0

Answered
Trying to save part of a filename that is being read into a variable as the name of the output file
Try something like this: function xyz(filename,a) [fpth,name,ext] = fileparts(filename); save(fullfile(fpth,[name,'a'...

8 years ago | 0

Answered
how to circularly shift the entire elements of a matrix
>> b = a.'; >> b(:) = b([end,1:end-1]); >> c = b.' c = 9 1 2 3 4 5 6 7 8

8 years ago | 0

Answered
how to solve the error "Not enough input arguments." please tell me how can I solve this problem
*Do NOT use the big green "Run" button.* That button is the worst design decision in the history of MATLAB: *ignore that button*...

8 years ago | 0

| accepted

Answered
how to convert decimal to binary ?
>> dec2bin(randi([1,1000],5,1),10) ans = 1101100000 1000010111 1100010100 0000100001 1110110000 And to co...

8 years ago | 0

| accepted

Answered
How to calculate mean on data from cell array of 3D struct array?
cat(3,Data_output{1}(:,6,1).dom_freq_PRSA_down) take the mean as appropriate, e.g.: mean(...,2) _"do you know how ...

8 years ago | 1

| accepted

Answered
Write a function called integerize that takes as its input a matrix A of integers of type double, and returns the name of the “smallest” signed integer class to which A can be converted without loss of information.
A simpler implementation: function text = integerize(A) if A >= intmin('int8') & A <= intmax('int8') typ = 'int8'...

8 years ago | 0

| accepted

Answered
How to fix the decimal alignment and save the file in ascii regular file?
Try this: M = [9.3,4.8,7.4,5.6;10.4,2.3,11.5,4.9;2.6,4.4,10.4,3]; fmt = repmat('\t%4.1f',1,size(M,2)); fmt = [fmt(3:e...

8 years ago | 1

| accepted

Answered
How to add zeroes to a matrix to make the dimensions same.
B(335,16) = 0; will automatically expand the matrix |B| to have size 335x16, the added elements have the default value (zer...

8 years ago | 1

Answered
Structure Indexing to Find Words
Dynamically accessing the fieldnames of nested structures is likely to be a very inefficient solution, and is far too complex fo...

8 years ago | 1

| accepted

Answered
To Find one element in a matrix or a Vector
any(V(:)==0)

8 years ago | 0

Answered
How to store data in different variables through loop?
This would be trivial with simpler, more efficient code, in just one line: C = num2cell(Data(1:28,2:21),1); and then acc...

8 years ago | 0

Answered
Sort rows based on number of 1's in each row.
>> A = [1,1,0,1;1,0,0,0;1,0,1,0;1,1,1,1]; >> [~,idx] = sort(sum(A,2),'descend'); >> A(idx,:) ans = 1 1 1 ...

8 years ago | 0

| accepted

Answered
Variable disappears when using it
@Vicki Ly: the _best_ answer ( _best_ in the sense fastest, neatest, least buggy, best practice as recommended by the MATLAB doc...

8 years ago | 0

| accepted

Answered
Too many files open error yet I am closing files
_"...you will see that after I complete reading each file I close the file using fclose(fID)."_ Nope. You actually only close...

8 years ago | 0

| accepted

Answered
What is the difference between mean(A,'omitnan') and nanmean(A) ?
There is no practical difference for your vector. Personally I would use |mean|, because |nanmean| is part of the Statistics ...

8 years ago | 2

| accepted

Answered
There's an error using input function in my computer , how do I solve it?
The error message is telling you that you have a file named |input|: have a look at the second line of the error message: what d...

8 years ago | 0

| accepted

Answered
How can I retrieve an element from this array of functions, as a matlabFunction?
Use a cell array to store function handles: C{1} = @(t,y) 10*(y(2)-y(1)); C{2} = @(t,y) y(1)*(28-y(1))-y(2); C{3} = @(t,...

8 years ago | 1

| accepted

Answered
parfor is slower than for
_"I don't see a reason why parfor should be slower than for."_ I don't see a reason why |parfor| should be faster than |for|....

8 years ago | 0

| accepted

Answered
Executing eval in function handle ?
This is a classic example of how the decision to use |eval| to access variables just makes code more complex and introduces more...

8 years ago | 2

| accepted

Answered
I have a cell array of size 1x934 and each cell has 160x160x96 double. I want to make a cell array of 1xn (n i think it is 89664) where each cell has 160x160
*Method one: concatenate into one numeric array, then split.* This will not work of you do not have enough memory for the comple...

8 years ago | 0

| accepted

Answered
Create a loop with string
Using _command syntax_ with <https://www.mathworks.com/help/matlab/ref/load.html |load|> is one of the main bugs in the code: as...

8 years ago | 0

Answered
How to display averages in new array?
This is easy in just a few lines. B = [... 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000...

8 years ago | 0

Answered
How do I format a .txt file I've created?
%15:9e is not a valid format string. Perhaps you meant to write a decimal point: %15.9e

8 years ago | 0

| accepted

Answered
Trying to do repeat math on multiple variables...
David Fletcher already showed the best way of doing this, which is to use MATLAB efficiently with one numeric array. If you real...

8 years ago | 0

Answered
how to write multiple of 7 from 0 to 200 in matlab
0:7:200

8 years ago | 0

Answered
Divide a matrix with an array along a specific dimension
Once you make the sizes compatible you can do this using standard methods without any loop. Use |permute| or |reshape| to get th...

8 years ago | 1

| accepted

Answered
How can I show variable index in a for loop?
_"I have 100 matrices, name x1, x2, ..., x100. I want to do the below process for all 100 variables using a "for loop""_ Acce...

8 years ago | 0

| accepted

Load more