Answered
Extract 2D matrix from 3D matrix with different lengths.
For just one matrix use either A = reshape(B(:,1,:),17,[]); or A = permute(B(:,1,:),[1,3,2]); For all of the mat...

8 years ago | 1

| accepted

Answered
How to use cell2mat for specific elements of cell array?
C = cell2mat(B(:,1:3)); C = C(:,2:3); _"What am I missing here?"_ Several things: firstly, that the |B{...}| syntax c...

8 years ago | 0

| accepted

Answered
How to find a minimum in this matrix ?
I have no idea how this will compare to using a few loops: A = randi(999,8,7,6,5,4,3); % fake data in 8x7x6x5x4x3 array. ...

8 years ago | 1

| accepted

Answered
Merging contents of multiple MAT files
To read the files in the correct order download my FEX submission natsortfiles: https://www.mathworks.com/matlabcentral/fileexc...

8 years ago | 0

| accepted

Answered
format data into string and write a txt file
A cell array of numeric vectors is quite inconvenient to work with, so the first thing to do is convert it to a much easier to u...

8 years ago | 0

| accepted

Answered
How to use a variable only defined in a function in your script?
Your usage of the function |angle| has several bugs, in particular: # You do not call |angle| with any output arguments, alth...

8 years ago | 0

Answered
how to find common values in two matrix for particular column?
You don't need to use a loop: >> sum(permute(A,[3,2,1])&permute(B,[2,3,1]),3) ans = 1 0 1 2 0 1 2 ...

8 years ago | 1

Answered
extracting numbers with different decimal extention
>> S = 'OutputY: 35,40 50 57,80 57 54,71 58,73 61,01 61,67 60,02 57,57 57,51 61,11 64,55 ...

8 years ago | 0

| accepted

Answered
Assigning small matrices in a large matrix in parfor loops
R = 20; N = 3; C = cell(1,N); parfor ii = 1:N A = zeros(3,3); for jj = 1:3 if jj == 1 ...

8 years ago | 0

| accepted

Answered
Replace for loop with matrix function, for function acting on matrix columns
Using <https://www.mathworks.com/help/matlab/matlab_prog/compatible-array-sizes-for-basic-operations.html implicit scalar dimens...

8 years ago | 2

| accepted

Answered
How to get selected folders from multiple folders in a directory?
To randomly select four folder names: D = 'path of the directory where the folders are'; S = dir(fullfile(D,'*')); X ...

8 years ago | 1

| accepted

Answered
Loading a variable from deferent .mat files selected using GUI matlab
>> new.X1_BA_time = 1:3; >> new.X1_DE_time = 4:6; >> new.X1_FE_time = 7:9; >> C = fieldnames(new); >> X = cellfun(...

8 years ago | 1

| accepted

Answered
create a vector with 10 to power negative number
All you need is this: 10.^(0:-1:-16)

8 years ago | 1

| accepted

Answered
sub2ind Get values of 3D matrix using an index vector
Given: A = 37x30x100000 matrix C = 37x1 vector of column indices *Method one: |ndgrid|:* S = size(A); [Rx,~,P...

8 years ago | 0

Answered
Alternatives for using EVAL to access data in multi-layered struct?
One simple solution is to use <https://www.mathworks.com/help/matlab/ref/getfield.html |getfield|> and <https://www.mathworks.co...

8 years ago | 2

| accepted

Answered
even after using fopen, still giving negative fid. how to get a valid fid?
You need to actually pass the filename to |fopen|: fnm = fullfile(matlabroot,'1.txt'); [fid,msg] = fopen(fnm,'r'); as...

8 years ago | 0

Answered
Assess element in struct which filed name contains '.'
You will need to use a <https://www.mathworks.com/help/matlab/matlab_prog/generate-field-names-from-variables.html dynamic field...

8 years ago | 0

| accepted

Answered
sprintf only get the first character in a string array
_"Why does it happen and how I can fix this?"_ Because |[]| is a _concatenation_ operator, not a list operator as some beginn...

8 years ago | 0

| accepted

Answered
How do I rename a variable, as it changes in a Loop
This is easy, as long as there is only *one* variable loaded from each |.mat| file: for k = 1:60 F = sprintf('Data%d...

8 years ago | 1

| accepted

Answered
Hi there! I'm just starting with matlab, so this question may seem a little too easy.
_"Can I return a vector from a function?"_ Of course. _"If yes, what syntax should I use?"_ Nothing special, exactly th...

8 years ago | 1

| accepted

Answered
converting a decimal number to its binary.
>> N = pi; % example number >> S = num2hex(N) S = 400921fb54442d18 >> X = sscanf(S,'%1x'); >> B = num2cell(dec2bin...

8 years ago | 0

Answered
How to pass a variable from one GUI to other GUI
In GUI1, where |d| is the data that you want to transfer: setappdata(0,'mydata',d); IN GUI2: d = getappdata(0,'myda...

8 years ago | 0

Answered
Unable to read MAT-file E:\my_file.mat: not a binary MAT-file.
_"How can I solve this problem?"_ The so-called |.mat| files at <https://github.com/lokesh1agarwal/SDI> are NOT MATLAB |.mat|...

8 years ago | 0

| accepted

Answered
Sort with respect to identical elements in a column.
>> a = [51,1.5,3.8;52,1.8,9.6;53,2.1,8.8;51,3.5,9.9;54,8.5,10.23;51,1.5,3.8] a = 51 1.5 3.8 52 1.8 9.6 5...

8 years ago | 1

| accepted

Answered
Is there a function that populates a matrix whose minor diagonal are all the same?
Use <https://www.mathworks.com/help/matlab/ref/hankel.html |hankel|>: >> V = [1,7.9,100,18.2,-3.4]; >> hankel(V(1:3),V(3...

8 years ago | 0

| accepted

Answered
Change the value of a matrix element based on the index given in another matrix
*Method one:* |sub2ind|: >> a = zeros(3); >> c = [1,3,2]; >> r = 1:size(a,1); >> a(sub2ind(size(a),r,c)) = 1 a ...

8 years ago | 0

| accepted

Answered
find a same element inside a cell
You could do this in two lines, but here I show it on four lines: >> A = {[1,2,5],[2,3,4],[1,2,4,5],[4,7,9],[1,2,4,5,6,9,10...

8 years ago | 1

Answered
When I run my function I want a row vector not a column
One simple solution is to use subscript indexing (but this will be quite inefficient): function n = num(k) n(1,1) = 1; ...

8 years ago | 0

| accepted

Answered
Why is Movefile creating a folder instead of renaming a file?
When renaming a file using <https://www.mathworks.com/help/matlab/ref/movefile.html |movefile|> you can only specify *one* file ...

8 years ago | 0

| accepted

Answered
Function Call not working properly
You probably want to be using logical indexing rather than |if|: function y = fun(x) y = zeros(size(x)); idx = x>5...

8 years ago | 0

Load more