Answered
fprintf command output and extra output
You used the wrong operator. If you want to print to string, use sprintf. "Where is the output=15 coming from..." The fprintf ...

7 years ago | 0

| accepted

Answered
how to remove the repetitive elements from a structure
Data: >> a = struct('position', {[200 300 1],[300 200 1],[250 250 0.5],[230 280 0.6],[300 200 1],[270 150 1]}, 'cost', {[50;90]...

7 years ago | 0

Answered
Help with nested structure
This would be much easier if you had designed your data better. In particular, rather than using nested structures (which are r...

7 years ago | 0

| accepted

Answered
While loop with for loop problem
Perhaps you meant something like this: D = [3 0 0; 0 2 0; 0 0 1]; b = [0; 1; 0]; L = [0 0 0; 1 0 0; 0 1 0]; U = [0 1 0; 0 0 ...

7 years ago | 1

| accepted

Answered
Opening mat files with uiopen and copying data to array
It seems that whoever created those .mat files unfortunately named each structure with the same name as the filename, which just...

7 years ago | 0

| accepted

Answered
How do I extract the same field from diferent struct files with names like AAA_1, AAA_2... AAA_n?
I suspect that ScanImage is badly written and saves variables (e.g. structures) with a different name in each .mat file. This ma...

7 years ago | 1

| accepted

Answered
Average of several (different, across) structures
Fake data in scalar structures: S1 = struct('A',randi(99,4,3,2),'B',randi(99,4,3,2)); S2 = struct('A',randi(99,4,3,2),'B',rand...

7 years ago | 2

| accepted

Answered
Keeping record of Number of concatenated files
Inside your loop: N = ... the total number of files. C = cell(1,N) for k = 1:N M = ... import the matrix here. M(:,...

7 years ago | 1

| accepted

Answered
Adding certain 'parts' of two matrices
B(2:3,2:3) = A

7 years ago | 0

| accepted

Answered
How to find out whether there is a repetitive element in the columns of a matrix?
"I just want to know whether there is or not." >> any(diff(sort(a,1),1)==0,1) ans = 1 1 0

7 years ago | 2

Answered
TUTORIAL: Why Variables Should Not Be Named Dynamically (eval)
Alternative: save the Fields of a Scalar Structure The save command has an option for saving the fields of a scalar structure a...

7 years ago | 4

Answered
Finding arrays above threshold value
Fake data: AT(1).AX = rand(1,370); AT(2).AX = rand(1,1007); AT(3).AX = rand(1,3957); AT(4).AX = rand(1,6309); AT(5).AX = ra...

7 years ago | 1

| accepted

Answered
How to Convert a column with Char in Cell matrice to Number?
You almost got it right, you just need to split the numeric array into a cell array so that it can be allocated back to the cell...

7 years ago | 1

| accepted

Answered
Could anyone help me how to solve the issue.
Using very basic MATLAB indexing: A = {[1,2],[3,4],[7,5,6]}; N = numel(A); Z = nan(1,N); for k = 1:N Z(k) ... your code...

7 years ago | 0

| accepted

Answered
Create a 20x24 matrix with each individual column with random integers without duplicate
You do not need a loop, here is a much simpler solution in just one line: >> [~,M] = sort(rand(20,24),1) M = 16 20 17 ...

7 years ago | 0

Answered
How to dissect a file path and keep extension Matlab
Do NOT use path as a variable name! This shadows the important inbuilt path function. To get the file extension use fileparts: ...

7 years ago | 1

| accepted

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

Load more