Answered
For loop skipping with if statement
This is a linear interpolation. This is implemented without a loop already: pk = [1, 2; 3, 0; 4, 0; 5, 3; 7, 2; 10, 0; 13, 5]; ...

3 years ago | 0

Answered
How to run a function within another function with specified input?
Convert the scripts S1 and S2 to functions, which accept these inputs. Then: x3 = get(handles.cbS2,'Value'); x4 = get(handles....

3 years ago | 0

| accepted

Answered
Structure of array: deletion of null elements
S = exp_value; % Just for readability remove = (S.f_avg(:, 1) == 0); fields = setdiff(fieldnames(S), {'f_avg'}); % All...

3 years ago | 0

| accepted

Answered
Naming tables inside a for loop
This is the most frequently asked question in this forum. The answer is easy: Don't do this. It is a shot in your knee. See: TU...

3 years ago | 0

| accepted

Answered
How to programmatically delete a folder with content to recycle bin as a whole
Using another folder instead of the recycle bin has severe advantages: The recycle bin fails, if the path name of the deleted f...

3 years ago | 0

Answered
Running Average of a large data set
A = readmatrix(filename); A(:, 3) = movmean(A(:, 2), 101);

3 years ago | 0

Answered
Problems converting folders in a directory from cell array into individual nested structures.
The field names cannot contain a dot. Remove the dots: ... for i = 1:length(subFolderNames) name = strrep(Folders(i).Fold...

3 years ago | 0

| accepted

Answered
How to use cumsum function?
loadValue = [0;50;20;10;5;30;12;8;20;30;5]; capacity = 300; mat = capacity(1,:) - cumsum(loadValue); for i = 1:numel(l...

3 years ago | 0

| accepted

Answered
Random lines confined in a 3d box
figure; axes('XLim', [-0.1, 1.1], 'YLim', [-0.1, 1.1], 'ZLim', [-0.1, 1.1]); hold('on'); view(3) nLine = 100; % A cube has ...

3 years ago | 0

| accepted

Answered
How to load portions of .dat file
[fid, msg] = fopen(FileName, 'r', 'b'); assert(fid > 0, msg); while true data = fread(fid, [3, 30000], 'uint32'); if...

3 years ago | 0

Answered
How to properly call a function from another matlab-file?
zeros(x1, length(tol)) creates a matrix of zeros with x1 rows and length(tol) columns. If x1 is an integer value, this works. Bu...

3 years ago | 2

| accepted

Answered
Using diff() or gradient() or other methods to solve the local slope of a set of discrete point?
load x.mat load y.mat slope1 = gradient(y); slope2 = diff(y) ./ diff(x); slope3 = gradient(y, x); % Consider x in the s...

3 years ago | 0

| accepted

Answered
Why do I get "Array indices must be positive integers or logical values" error when reading an image?
Did you define "imshow" as a variable? whos imshow which imshow -all To clear it: clear imshow But it is strange, that the ...

3 years ago | 0

Answered
how to add "drawnow" function in it?
The answer is trivial: simply add a drawnow command at the end of the code. But the question remains, what the purpose is. You ...

3 years ago | 0

Answered
Compact way to calculate the centroid of a boundary of a set of points
The centroid of the boundary is the mean value of the coordinates: x = rand(40, 1).^2; % More points on the left y = rand(40,...

3 years ago | 2

| accepted

Submitted


Rotation Matrix
Rotation matrix in 2D, 3D and N-D

3 years ago | 2 downloads |

5.0 / 5

Answered
Rotate Basis Vectors Programmatically
See: FEX: Rotation Matrix This creates N-dimensional rotation matrices.

3 years ago | 0

| accepted

Answered
How to use cumsum function?
CG = 25; C = 0; for i = 1:size(B, 1) if B(i, 5) < 200 if C == 0 C = CG; else C...

3 years ago | 0

Answered
How to speed up this calculation and remove loop(s)?
There is a very small potential for optimizing in the posted code: for row = 1:size(oFD,1) c1 = oFD.PS(row); c2 = oFD...

3 years ago | 0

| accepted

Answered
Access data in cell and save as vector with corresponding variable name
Data = struct(); % [EDITED], was: struct([]); for k = 1:numel(tableCell) C = tableCell{k}; NameList = T.Properties.V...

3 years ago | 0

| accepted

Answered
Vertcat error when concatenating images in loop
vertcat(Sro) concatenates Sro with nothing. What is the purpose of this command? Ask Matlab, what the problem is: for i = 1:le...

3 years ago | 0

Answered
csv file to text file
% [UNTESTED CODE!] function Value = GetCSVElement(File, R, C) % INPUT: File: File name % R: Row index of wanted element. 1 r...

3 years ago | 0

Answered
loop over variable with different characters
This shows, that you have created a bunch of variables and stored important information in the name of the variables. This desig...

3 years ago | 0

| accepted

Answered
Efficient way to assign indices to variables in a matrix
[~, Result] = ismember(A, B(:, 4)); A look up table is even faster: Instead of searching the element A(i,j) in B(:, 4), create ...

3 years ago | 1

Answered
Why sprint doesn't show a zero value from an array?
Reduce the clutter: a=[1:450:2251]; % Easier: a = 1:450:2251; [] is Matlab operator for a concatenation. [1:450:2251] concat...

3 years ago | 0

| accepted

Answered
How to interleave data from 2 doubles of differing length?
A=[1420;2956;4492;6028]; B=[2960;3152;3344;3536;3728;3920;4112;4304;4496;4688;4880;5072;5264;5456;5648;5840]; [C, idx] = sor...

3 years ago | 0

| accepted

Answered
Load multiple *.mat files and save outputs using loop without overwriting the previous file
filePattern = fullfile(myFolder, '*.mat'); theFiles = dir(filePattern); nFiles = numel(theFiles); % not size() Out = cell...

3 years ago | 0

| accepted

Answered
How to know the exact colour after a level of transparency being applied?
The color you see through a semitransparent element depends on the background. The rule is simple: alpha = rand; % ...

3 years ago | 0

| accepted

Answered
Remove the 1x1 Cell Array from the Cell Array
If you want D{1} = [2, 1], use: D{1} = [2, 1] % or equivalently D = {[2, 1]} Expanded: D = {[2,1], [1,2,0]} D{1} D{2} Ma...

3 years ago | 0

| accepted

Answered
code no good :(
areaOriginal = area(widthOriginal,thicknessOriginal); This creates a diagram and returns the handle to the graphics object. ar...

3 years ago | 0

Load more