Answered
Convert time to datenum
It is not required to navigate to data directories to read data: D = 'Path of the directory where the MAT files are saved'; S ...

7 years ago | 1

| accepted

Answered
Multidimensional matrix to use for loop
for k = 1:3 X(:,:,k) end If you want to split into a cell array: a = cell(1,3); for k = 1:3 a{k} = X(:,:,k) end ...

7 years ago | 0

Answered
How to make a for loop with matrices using n?
>> n = 10; >> A = toeplitz([2,-1,zeros(1,n-2)]) A = 2 -1 0 0 0 0 0 0 0 0 -1 2 -1 0 0 0 0 ...

7 years ago | 0

| accepted

Answered
Rename a variable using a string
"Rename a variable using a string" Why bother? Both load and save work with scalar structures, which makes your task easy: S =...

7 years ago | 0

| accepted

Answered
Matlab plots my equation wrong
MATLAB has plotted exactly what you asked for, where the y-range ranges over: >> x = -20:0.1:20; >> y = x.^10-1; >> max(y) a...

7 years ago | 1

| accepted

Answered
what does this code represents? and why rand() has no value between parentheses?
It defines a function which returns either 1 or 0, where 1 has ~=20% probability. Simpler code: customer = @()+(rand(1)<=0.2); ...

7 years ago | 0

| accepted

Answered
please in need help , how can i get all the possibile combination 111 112 121 122 211 212 221 222 for matrix A in matlab , than u
>> R = [0.5807,0.5192;0.879,1.5083;0.6836,1.5183] R = 0.5807 0.5192 0.8790 1.5083 0.6836 1.5183 >> [X,Y,Z] = ndgri...

7 years ago | 0

Answered
How can I get and write data from text file?
This code sorts the file data into one cell array C, where each cell in C contains the summer data for one year. The summer star...

7 years ago | 0

| accepted

Answered
Error using cat. Dimensions of arrays being concatenated are not consistent.
That is not very well designed code: the regexp is overkill, and the str2num with cellfun is likely not very efficient (as well ...

7 years ago | 1

| accepted

Answered
Error: Cannot convert double value 5 to a handle
Most likely sch(ii,1), ii, and h are actually all different classes which cannot be concatenated together. You could easily use...

7 years ago | 1

| accepted

Answered
add zero elemant inside cell
Simple indexing does exactly what you need: >> A={[95],[112],[98],[84],[69],[121],[108]}; >> B={[1,2,4],[4,3],[6,9,98],[3,7,88...

7 years ago | 0

| accepted

Answered
How do I find closest values between 2 matrices?
Using basic MATLAB only (i.e. without knnsearch from the Statistics Toolbox): >> true_ang = [-40,-20]; >> all_angs = [30.80304...

7 years ago | 0

Answered
Passing by reference vs value
"Passing by reference vs value" Neither. MATLAB is more intelligent that either of those. MATLAB uses something called "copy on...

7 years ago | 1

| accepted

Answered
Plotting based on a for loop from a cell array
xyz = 'XYZ'; figure() for k = 1:3 subplot(3,1,k) plot(UA_SEG{:,['Acc',xyz(k)]}) end https://www.mathworks.com/help...

7 years ago | 0

| accepted

Answered
how to create a vector with the different sum of two elements of another vector?
No need to use a loop, some simple indexing works perfectly: >> v = [1,2,3,4,6,8]; >> v(1:2:end)+v(2:2:end) ans = 3 7...

7 years ago | 1

| accepted

Answered
Save variable as string from user input
There are two overlapping issues here: The non-robustness of string evaluation (which was covered in your other question). Ther...

7 years ago | 4

| accepted

Answered
is it possible to divide a decimal number into 3 decimal numbers?
>> N = 1000; >> R = 3; >> C = R+R*fix(log2(N)/R); >> M = reshape(dec2bin(N,C),[],R).' M = 0011 1110 1000 >> bin2dec(M) ...

7 years ago | 0

| accepted

Answered
MATLAB : How to keep output values after using return
"What should I do to pass the values of [S,r1,r2,c1,c2] to the caller function after using return?" Nothing special at all. As ...

7 years ago | 0

Answered
How to read the details of a '1×1 struct' Cell Array?
Both cell arrays and structure arrays are kinds of container arrays, i.e. they can contain other arrays. In your case you actual...

7 years ago | 1

| accepted

Answered
How can I call the variables of MATLAB workspace from a function?
"I don't seem to be able to do it when I am inside a funtion and don't know the name of the variables prior to running the progr...

7 years ago | 1

Answered
Sort first column of a 5x2 matrix but keep the rows intact after sorting
Use sortrows: >> V = [13,11,15,26,20]; >> M = [V;1:numel(V)].' M = 13 1 11 2 15 3 26 4 20 ...

7 years ago | 0

| accepted

Answered
How to iteratively add elements to a cell array without clearing previous elements?
I suspect that you forgot to actually store the handles data after you made changes to it. The handles structure inside the call...

7 years ago | 0

Answered
Splitting Cell Arrays by Delimiter
There is no need to split, just count the commas, e.g.: >> s = {'AAAA,BBBB'; 'CCCC,DDDD,EEEE'; 'FFFF'}; >> n = 1+cellfun(@nume...

7 years ago | 0

Answered
Converting a printed set of data to a structure or structure array
The simplest solution that satisfies your description: S = load('olympics.mat','gold', 'silver', 'bronze', 'countries');

7 years ago | 0

Answered
Shifting position of an element in a vector from 1st to last
Here is a general solution for any sized vector (not in a single command though): >> N = 5; >> V = 1:N V = 1 2 3 4 ...

7 years ago | 1

| accepted

Answered
NEED HELP! in load a text file containing the first one million digits of Pi.
This code imports all of the digits in around one second: >> fid = fopen('data.txt','rt'); >> vec = fscanf(fid,'%1d'); >> fcl...

7 years ago | 1

| accepted

Answered
Vectorization of for loop
In three lines, no loop: >> new_im = flipped_im; >> idx = new_im(:,:,1)>new_im(:,:,2) | new_im(:,:,1)>new_im(:,:,3); >> new_i...

7 years ago | 1

| accepted

Answered
How do you save variables to vectors and plot them?
You define h to have values that are NOT positive integer: for h=0:.5:105 which means that you cannot use h as an index. The s...

7 years ago | 0

Answered
equality between different number of variables problem
Where C is your cell array: isequal(C{:}) Learn how this works by reading the isequal documentation, and these: https://www.m...

7 years ago | 0

| accepted

Answered
How to hide alphabets behind asterisks for password in GUI?(Creating GUI using guide)
Note that MATLAB is not a secure tool suitable for handling passwords: any arbitrary function can be trivially overloaded. http...

7 years ago | 2

Load more