Answered
I get Arrays have incompatible sizes for this operation with an elseif statement what do i do?
The == operator compare the arrays elementwise. Therefore the arrays on the left and right must have the same number of characte...

4 years ago | 0

| accepted

Answered
How to assign a value to a variable in for loop?
This is the most frequently asked question from beginners. Professional programmers give the simple and not expected answer: Don...

4 years ago | 0

| accepted

Answered
How to save all the images generated from the for loop?
Remove the line f=figure; at the bottom of the loop, but open a new figure on top: for i=1:length(fileList) FigH = =figu...

4 years ago | 0

| accepted

Answered
Proper if/else statement in appdesigner
Ref = app.rr_camber_ref.Value; Value = app.rr_camber.Value; if abs(Value - Ref) / abs(Ref) < 0.05 app.Lamp_rr_camber.Co...

4 years ago | 1

| accepted

Answered
How do I change the font type in the axes?
Ax1H = subplot(1,2,1); Ax1H.FontName = 'Serif'; Ax1H.FontSize = 15; Ax2H = subplot(1,2,2); Ax2H.FontName = 'SansSerif'; Ax2...

4 years ago | 0

Answered
Match two columns with names/strings that are not 100% identical
Pool = {'NAME123ABC', 'NAME2XYZ', 'NAME3333', 'NAME ZZZ'} Data = {'XYZ', 'Name1ABC', 'abc', '123A', 'AAA', 'ABC ABC', 'Name1 AB...

4 years ago | 0

Answered
Matlab takes long time to start, also it lags so much and windows task manager shows very high memory usage. How to fix this?
Do you really need all toolboxes? This is a massive overkill. You can run the installer again and deselect the toolboxes, you d...

4 years ago | 1

Answered
Processing each data automatically in a loop
If you do not want to call uigetfile, remove this command: pathname = 'C:\Your\Folder'; for i = 0:287 filename = fullfile...

4 years ago | 0

| accepted

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]; ...

4 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....

4 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...

4 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...

4 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...

4 years ago | 0

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

4 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...

4 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...

4 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 ...

4 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...

4 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...

4 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...

4 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 ...

4 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 ...

4 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,...

4 years ago | 2

| accepted

Submitted


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

4 years ago | 766 downloads |

5.0 / 5

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

4 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...

4 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...

4 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...

4 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...

4 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...

4 years ago | 0

Load more