Answered
Looping within a structure
You can easily loop over the fieldnames: F = fieldnames(mystruct); for k = 1:numel(F) A = mystruct.(F{k}); ... do wh...

7 years ago | 0

| accepted

Answered
How to convert a structure array into vector
S(1).F1 = [1,2,3,4,5]; S(2).F1 = [10,20]; S(1).F2 = [2,4,6,8,10]; S(2).F2 = [150,200]; F = fieldnames(S); C = num2cell(stru...

7 years ago | 1

| accepted

Answered
Storing multiple matrices created by multiple executions of a function
Method one: input/output arguments: function [A,B] = mainfun(N) [A,B] = recfun(N,{},{}); end function [A,B] = recfun(N,A,B) ...

7 years ago | 0

| accepted

Answered
How can I find consecutive digits seperated by spaces?
Simple solution using a dynamic match expression: >> str = '1 1 1 4 4 6 7 7 7 7'; >> out = regexprep(str,'(\d)(??( $1)*)','${n...

7 years ago | 1

| accepted

Answered
Output from nested struct into numerical / string array
string({mystruct.somenesting.objecttype.name}) cat(1,mystruct.somenesting.somethingelse.size) % ^ change this to suit the si...

7 years ago | 0

| accepted

Answered
convert a 10x2 matrix into x,y coordinates
>> M = [1,2;3,4;5,6] M = 1 2 3 4 5 6 >> V = 1:size(M,1); >> fprintf('(x%d,y%d)=(%d,%d)\n',[V;V;M.']) (x1,y1)=(1,...

7 years ago | 0

| accepted

Answered
tic, toc, apear to be reporting incorrect times when called in App Designer button callback
Try specifying the output variable: t = tic(); ... toc(t) Or record the time yourself: tstart = now(); ... now()-tstart ...

7 years ago | 1

| accepted

Answered
Convert single string with many numbers to vector
Very simple, very efficient, no evil eval: >> hue = '10 20 30 40 50'; >> vec = sscanf(hue,'%f',[1,Inf]) vec = 10 20 3...

7 years ago | 1

Answered
Row interpolation by adding data at end of the matrix
>> V = interp1(1:18,d,1:20,'pchip','extrap'); >> V(:) ans = 24.1615256950601 24.1615256699363 24.1615256438020 ...

7 years ago | 0

| accepted

Answered
assign header line value to variable
A very simple and very efficient method without eval and without shadowing the inbuilt size: >> str = 'size=256 256 256;'; >> ...

7 years ago | 0

Answered
question about vectorization using indexes
Note that ind and b must be transposed for this to work: >> a = [4;2;1;3;1;4;4;0]; % must be column! >> ind = [1,0;2,3;4,0;3...

7 years ago | 0

| accepted

Answered
Change from set notation to dot notation
The MATLAB documentation explains that dot-notation only applies to scalar objects: https://www.mathworks.com/help/matlab/creat...

7 years ago | 0

| accepted

Answered
How to read a file containing non numerical characters and commas?
opt = {'HeaderLines',22,'MultipleDelimsAsOne',true}; str = fileread('He_2.txt'); str = strrep(str,',','.'); C = textscan(str,...

7 years ago | 0

Answered
Error when taking an exponent from a large data set
x2 = exp(double(x1));

7 years ago | 0

Answered
how to avoid using a name to a specific file in GUI
Your explanation is not clear if you know Specificname in advance or not, or how many variables there are saved in the .mat file...

7 years ago | 0

| accepted

Answered
Import .txt and save as .mat with conditions
As you did not supply an example file I created my own (attached). [fid,msg] = fopen('test.txt','rt'); assert(fid>=3,msg) C =...

7 years ago | 0

| accepted

Answered
convert milliseconds (ms) to seconds (s)
You can change the format of how numbers are displayed, e.g. "shortG" >> format shortG >> ms/1000 ans = 1600.9 ...

7 years ago | 1

| accepted

Answered
From a given vector create all combinations possible
>> V = [5,10,15]; >> [X,Y] = ndgrid(V); >> M = [Y(:),X(:)] M = 5 5 5 10 5 15 10 5 10 10 ...

7 years ago | 0

| accepted

Answered
Finding values of specific range from table row or column
>> A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502].' A = 12345 NaN NaN NaN NaN ...

7 years ago | 2

| accepted

Answered
Regular Expression to timestamp
>> rgx = '(?<H>\d*)(?(1):)(?<M>\d+):(?<S>\d+)\.(?<F>\d+)'; >> regexp('11:32.456',rgx,'names') ans = H: '' M: '11' ...

7 years ago | 0

Answered
Rescaling a variable with NaNs
>> M = randi(7,3,5); >> M(randi(numel(M),1,3)) = NaN M = 6 7 7 6 4 3 NaN 5 NaN 6 ...

7 years ago | 1

| accepted

Answered
how to remove the last column in the matrix?
>> A = [2,4,2,4,2,6,8] A = 2 4 2 4 2 6 8 >> B = A(1:end-1) B = 2 4 2 4 2 6

7 years ago | 0

| accepted

Answered
Fill an array after a for loop
These two changes make the code run without error: G = zeros(nraw,numel(x)); and G(i,:) = x; Whether it is correct only you ...

7 years ago | 0

| accepted

Answered
Convert a vector in Character array after a for loop
Avoiding character manipulations using basic indexing: >> x = [1,2,3,1]; >> V = 'A':'Z'; >> V(x) ans = ABCA

7 years ago | 0

| accepted

Answered
How to define and store string to matrix or array
With a simple cell array: N = 3; C = cell(1,N); for k = 1:N x = ... your code C{k} = x; end https://www.mathworks...

7 years ago | 3

| accepted

Answered
draw a graph from cell arrays
plot((Y{i},position);); % ^ ^^ not valid syntax should be plot(Y{i},position); PS: in future please show th...

7 years ago | 0

Answered
Round in a cell array that also contains string
idx = cellfun(@isnumeric,C); C(idx) = cellfun(@(x)round(x,N),C(idx),'uni',0)

7 years ago | 0

| accepted

Answered
How can I generate random single precision (float32) numbers ?
This generates all possible singles: >> V = ['0':'9','A':'F']; >> X = randi(16,1,8); >> V(X) ans = 7B3A5B5F >> N = typecast...

7 years ago | 1

Answered
How can I create a fullpath from images of different subfolders?
Do not use path as a variable name (you shadow the inbuilt function of that name). Do not concatenate strings to build paths. ...

7 years ago | 0

| accepted

Answered
Using a Variable inside the name to save a file
fnm = sprintf('date_%s_task.jpg',ID); saveas(gcf,fnm); Note that obtaining and referring to explicit graphics handles is more ...

7 years ago | 0

Load more