Answered
Why does the text file does not show me lines printed on next lines even when i used '\n' while printing the data in Matlab?
You should fopen the file in TEXT mode: fid = fopen(....'wt') % ^ TEXT mode! Or alternatively stop using retr...

7 years ago | 0

| accepted

Answered
How to get the value of exponential power?
Just use log10: >> floor(log10(a)) ans = -12 -13 The correct answer is [-12,-13], not [12,13] (because these are the powe...

7 years ago | 1

| accepted

Answered
Write to text file
You fopen-ed the file in read mode and not write mode (because the default mode is read mode and you did not specify any other m...

7 years ago | 1

| accepted

Answered
Matrix with full combinations of vectors'/matrices' elements
>> A = [1;2;3]; % Column vector! >> B = [4,5;6,7]; >> C = [8,9;10,11]; >> D = [12;13]; % Column vector! >> An = size(A,1); ...

7 years ago | 0

Answered
Making a array that gives me this kind of data...?
>> xp=5; >> x1=1.5; >> depth=2.3; >> Xv = -xp:0.1:xp; >> Yv = min(0,depth*abs(Xv)/x1 - depth); >> plot(Xv,Yv,'-*')

7 years ago | 1

| accepted

Answered
Sum Numbers Excluding Zeros
Simpler solution using accumarray: >> x = [0,0,0,1,0,2,2,3,4,0,0,0,0,7,8,2,2,0,3,0]; >> y = cumsum(x==0 | [true,x(1:end-1)==0]...

7 years ago | 1

Answered
How to compare each element of an array with the rest of the elements for several rows independently?
Because each array has a different size you will have to use a cell array: A = [1 1,0,1,1,0;0,0,1,0,0,1;0,0,0,1,1,1;1,1,1,1,1,1...

7 years ago | 1

| accepted

Answered
Not enough input arguments
You need to parameterize the objective function supplied to fsolve: https://www.mathworks.com/help/matlab/math/parameterizing-f...

7 years ago | 2

Answered
How to edit a number in a text file and save a copy of the file multiple times?
vec = [23,5]; % new values cnt = 0; rgx = '^(\s*\S+\s+)(\S+)(.+gamma.+)$'; f1d = fopen( 'input_matlab.txt','rt'); f2d = fope...

7 years ago | 1

| accepted

Answered
What function returns (as an integer) the number of bits in a data type or class, e.g. returns 16 for 'int16' or 'uint16' variables, 32 (or whatever) for 'float' types, etc.?
>> A = single(0); >> S = whos('A'); >> S.class ans = single >> S.bytes*8 ans = 32 If you have non-scalar arrays to get th...

7 years ago | 2

| accepted

Answered
Find the index of given value in an array
Much simpler (and also works for multiple val values): interp1(array,1:numel(array),val) For example: >> array = [2,4,5,7,8,9...

7 years ago | 4

| accepted

Answered
realmax + 1 infinity?
Because the value 1 is nowhere near the smallest value that can be added to realmax to create a new value. You would need to add...

7 years ago | 3

| accepted

Answered
Function having string as argument
I would not recommend using a string to define the input function. A much more reliable way would be to write your code to acce...

7 years ago | 1

| accepted

Answered
How can i create a new vector with conditions?
>> d = [100,200,300;250,350,450;810,550,600;500,700,400] d = 100 200 300 250 350 450 810 550 600 500 700 40...

7 years ago | 2

| accepted

Answered
how to find similar points in two different matrices
Use ismembertol: >> X = ismembertol(M,N,'ByRows',true); >> C = M(X,:) C = 224 345

7 years ago | 0

| accepted

Answered
regexp for time - cannot guess it
This is easy with a conditional expression based on the fourth token (decimal point) match: >> rgx = '(?<hh>\d{2})(?<mm>\d{2})(...

7 years ago | 1

Answered
How can I use assignin and eval together in function
Your code concept forces you to write slow, complex, obfuscated, buggy, and hard to debug code: https://www.mathworks.com/matla...

7 years ago | 1

| accepted

Answered
How to create a loop
A geometric series really is simpler to write using vectorized code: k = (1+ge)/(1+y); e0 * k.^(0:13)

7 years ago | 0

Answered
Calculating the strangeness using k constant
>> a = [0.6164;3.1654;0.5745;2.9883;0.9381;2.1817]; >> c1 = sort(a(1:2:end)); >> c2 = sort(a(2:2:end)); >> K = 2; >> sum(c1(...

7 years ago | 0

Answered
Remove some numbers from an array and replace them with zero?
>> A = [4,4,4,4,6,6,6,6,6,6,2,2,3,3,3,5,5,5,5,5,3,3,3] A = 4 4 4 4 6 6 6 6 6 6 2 2 3 3 3 5 5 5 5 5 3 3 ...

7 years ago | 0

| accepted

Answered
Convert number to string problem
>> V = [9,8,0,-5,-6]; % your data should be in one array. >> S = sprintf(', %+g',V(1:end-1)); >> S = sprintf('The numbers are%...

7 years ago | 0

Answered
Process data from sequentially named folders each having a file with the same name
To get the subfolders in numeric order download my FEX submission natsortfiles: https://www.mathworks.com/matlabcentral/fileexc...

7 years ago | 0

| accepted

Answered
Alternative to for/while cycle
"a possible option should be the replacement of the for and while cycles with another option" Why do you think that the loops t...

7 years ago | 1

| accepted

Answered
Add some elements of one matrix with another
Using a straightforward loop: C = {[1,2;3,4],[5,6;7,8],[9,10;11,12],[13,14;15,16]}; A = cat(3,C{:}); % not strictly required, ...

7 years ago | 2

| accepted

Answered
how to insert data at a certain positions in .txt file?
str = fileread('test3.txt'); str = regexprep(str,'(")\s*(\d)','$1\n$2'); [fid,msg] = fopen('test4.txt','wt'); assert(fid>=3,m...

7 years ago | 1

| accepted

Answered
Finding Duplicate rows?
Simpler using hist (or its more recent equivalents): >> A = [1,2;2,3;2,1;3,5;4,6;5,3] % I added an extra row A = 1 2 ...

7 years ago | 2

Answered
Sort matrix by increasing values (with doubles) and return indices to then sort secondary cell structure
You appear to be overthinking things. If you want to sort something, just use sort: >> [wo,idx] = sort(weight(:)); >> do = dat...

7 years ago | 0

| accepted

Answered
Error using Cos, not enough input arguments
cos^2*(pi/2) % incorrect cos(pi/2)^2 % correct Your code has several other syntax errors, such as: Ox % what does t...

7 years ago | 0

| accepted

Answered
How to search for channel name and numerical data in resulting struct after importing multiple data files?
You are right to avoid dynamically accessing variable names (e.g. using eval, assignin, evalin, and load without an output varia...

7 years ago | 0

| accepted

Answered
Sorting from highest to lowest for a particular column
Simpler and no loops required with sub2ind: >> X = sub2ind(size(A),B(:,2),B(:,3)); >> C = [B(:,1),A(X),B(:,4:end)] C = 1...

7 years ago | 1

| accepted

Load more