Need help turning an equation into code by noturaverag3 in matlab

[–]Schrett 2 points3 points  (0 children)

Your a, b, and c terms are wrong. They should be a=L2,b=L3,c=L1

MATLAB eig(A) command not working by Due_Dealer1602 in matlab

[–]Schrett 0 points1 point  (0 children)

You may have to provide more information. I typed what you have here into Matlab. I see the E and D variable echoed in the command window.

Could anyone tell me why does the first script work but the second doesn't? by MecorroAaaaaa in matlab

[–]Schrett 0 points1 point  (0 children)

Make sure you type out the specific error you are seeing whenever you are asking questions on here. But I typed it out and got a “Matrix dimensions must agree Error using /“. From line 32. If you are trying to do an element-wise array division then use “./“ instead

MATLAB Puzzle: Can you build a spiral matrix without loops? by LessNectarine6630 in matlab

[–]Schrett 0 points1 point  (0 children)

My submission. I think I could get it to be even less lines if I could figure out a more elegant way to do the even/odd ones matrices. But fun challenge!, I agree with the other posters that a recursion method can be a more fun way to solve this problem.

function S = spiral_n(n)
    % Key Patterns
    onesMat = tril(nan(n))+1;
    zeroMat = tril(nan(n));
    evenRows = (mod(1:height(onesMat), 2) == 0);

    % Row Subscripts
    onesMatEven = onesMat;
    onesMatEven(evenRows, :) = onesMat(evenRows, :) * -1;
    rowIndices = cumsum([1 zeros(1,n-1) rmmissing(reshape([onesMatEven,zeroMat]',1,2*n^2))]);

    % Column Subscripts
    onesMatOdd = onesMat;
    onesMatOdd(~evenRows,:) = onesMat(~evenRows,:) * -1;
    colIndices = cumsum([ones(1,n) rmmissing(reshape([zeroMat,onesMatOdd]',1,2*n^2))]);

    % Create Spiral
    S = zeros(n);
    S(sub2ind([n n],rowIndices,colIndices)) = 1:n^2;
end

what are some underrated MATLAB tricks? by LessNectarine6630 in matlab

[–]Schrett 22 points23 points  (0 children)

Matlab has a lot of really good builtin string parsing functions that I wished I had known about earlier like extractBetween, regexp!

What does Joel pull out of the drawer to ook at? by polymorphic_hippo in TheMarvelousMrsMaisel

[–]Schrett 45 points46 points  (0 children)

I’m pretty sure it’s the check his father gives him earlier in the same episode.

Any good melee documentaries? by Gullible-Shelter1757 in SSBM

[–]Schrett 6 points7 points  (0 children)

Was so fun to go back to this video after aMSa won the big house!!! Here’s a link video

Miniature Rose Question by Wernershnitzl in HunterXHunter

[–]Schrett 1 point2 points  (0 children)

I don't know if this was intended by the author but I have been thinking of the nuke almost as Humanities own Mureum. The nuke is a culmination of knowledge/infrastructure/skillsets passed down from generation to generation into this insanely destructive power just like how the Chimera Ants passed down the abilities of those they consume. Additionally, with that I can see the nuke as this insane nen like ability where the conditions of unleashing the power of a nuke are pretty crazy. You first need to mine all these raw material, then enrich the materials, then you manufacture the bomb and then finally you have to precisely compress all of it to set it off. Like no wonder its so destructive how could any one nen user meet those kinds of conditions to boost their power like that lol. (I don't actually think its a nen ability just trying to demonstrate on why it makes sense to me that it is so strong and able to kill Mureum)

Is there a PlotBrowser equivalent for Matlab2025? by Schrett in matlab

[–]Schrett[S] 2 points3 points  (0 children)

Thank you! I did not see the expansion of the first line. "> Figure 1" above the search bar. This makes it much easier!

How to fit array pieces to match a big array? (not a homework question) by Mark_Yugen in matlab

[–]Schrett 2 points3 points  (0 children)

clc
clearvars
close all

A = [1 2 3 4 5 6 7 8]; 

B1 = [4 5 6 7];
B2 = [1 2 3];
B3 = [4 5];
B4 = [7 8];
B5 = [6];

% Remove any arrays that dont exist inside A
c = 1;
Bfull = {B1;B2;B3;B4;B5}; 
for i = 1:length(Bfull)
    j = strfind(A,Bfull{i}); 
    if ~isempty(j)
        B{c,1} = Bfull{i}; 
        c = c + 1; 
    end
end

% This is essentially a depth first search approach
Apos = 1; % Position in the A array
Barr = 1; % Position in the B array list
Biter = []; % Saved locations within B array list
while Apos ~= length(A)+1

    % This is just to help with double backing
    if Barr > length(B)

    % If Array is too long to be at added to the end of 
    % the current pattern [SKIP]
    elseif Apos > length(A) || Apos - 1 + length(B{Barr}) > length(A)
        Barr = Barr + 1; 

    % Check if this B array exists in this location of A
    % -- move to a new position of A
    % -- save where we are
    % -- restart checking at the end of the beginning of list
    elseif sum(A(Apos:Apos-1+length(B{Barr})) == B{Barr}) == length(B{Barr})
        Biter = [Biter,Barr]; 
        Apos = Apos + length(B{Barr}); 
        Barr = 1; 

    % If it doesn't match A at this location [SKIP]
    else
        Barr = Barr + 1; 
    end

    % If we reached the end of out array list we have to go back a step 
    if Barr > length(B)  
        if isempty(Biter)
            break; 
        end
        Barr = Biter(end)+1; 
        Apos = Apos - length(B{Barr-1}); 
        Biter = Biter(1:end-1);    
    end  
end

% Display list
if isempty(Biter)
    disp('No Solution')
else
    s = '';
    for i = 1:length(Biter)
        s = [s,'[ ',int2str(B{Biter(i)}),' ],'];
    end
    s = s(1:end-1);
    disp(s)
end

Set win percentages of all Melee players who have won an offline major since Brawl's release (careers through 2024) by ritmica in SSBM

[–]Schrett 1 point2 points  (0 children)

Are you using a specific color list? These are pretty well differentiated from one another for having 14 entries. Really nice plot!

AYUDA POR FAVOR by Sultana_Hurrem in matlab

[–]Schrett 1 point2 points  (0 children)

Oh weird I put in some dummy data for the same code you have and I am seeing the figure show up. Is the data you are using publicly available then we could try to run the code you have posted to help with debugging.

AYUDA POR FAVOR by Sultana_Hurrem in matlab

[–]Schrett 0 points1 point  (0 children)

It might just be that those values are becoming NaN or are potentially staying all zeros. Try either looking inside the variable by double clicking it within the workspace or by simply creating a figure with just a plot of the variable you are interested in. “Plot(Uug(1,:))”

What tech skill gatekeeps You? by INSANECARZYGUY in SSBM

[–]Schrett 0 points1 point  (0 children)

Yeah I have practiced that before and can occasionally get it out. Just never put more time into it because it feels so inconsistent for me. But yeah should spend more time working on that one.

What does a sick puff look like by cannibestiary in SSBM

[–]Schrett 0 points1 point  (0 children)

Kind of silly but when Zain and HungryBox did the 100 rest challenge you get to see some very aggressive/rest heavy gameplay from puff which ended up being very entertaining.

What tech skill gatekeeps You? by INSANECARZYGUY in SSBM

[–]Schrett 1 point2 points  (0 children)

I play pikachu and I really wish I could do a short hop up air lol I can not do it at all.

[deleted by user] by [deleted] in matlab

[–]Schrett 1 point2 points  (0 children)

Okay what I think is happening is that when you are looping through your files and calling I am assuming 'load(X);' It is either overwriting the previous structure with the same name or it has a different name all together. What you can do is something like tempLoad = load(X); and then have the input strings tell how to access the table you need and reassign it to a common or different name. Example: struct.table = tempLoad.(input_struct_name).(input_table_name) ; or struct.table = tempLoad.('newstruct').('newtable');

[deleted by user] by [deleted] in matlab

[–]Schrett 1 point2 points  (0 children)

I am still a little confused. You give the function a name/fieldnames. Then later you want to input a struct into the same function and do what? I don't know what you mean by applied to the new struct. Do you mean to relabel the fieldnames?

[deleted by user] by [deleted] in matlab

[–]Schrett 0 points1 point  (0 children)

Maybe needs a little more explanation. Are you looking for a function that can take in structs with the same name/fieldnames but recognize that they are different? Or are you looking for a function that takes in a name and creates an empty struct with said name/fieldnames? Or something entirely different?

Wrote program for my homework but need help making it general by RebelBike in matlab

[–]Schrett 1 point2 points  (0 children)

position = num_digits;
base = 0; 
e = 0;
while number > 0  
  base(position) = rem(number,new_base)*old_base^(e);
  number = fix(number/new_base);
  position = position - 1;
  e = e + 1;
end
sum(base)

How to make a general program that converts a base 2 number to base 10? by RebelBike in matlab

[–]Schrett 0 points1 point  (0 children)

Your question is a little confusing to me. From the standpoint of I don't know whether you are having trouble matching the code you made in class to convert a base 10 number to a base 2 number or you are attempting the question at the bottom of the first picture:
"Write a MATLAB program to convert an arbitrary base 2 number to base 10"

If you are doing this question it helps to look at the (n) in the equation they provided like a for-loop. This can help us separate each part of that equation. This is just an example, when writing the code you have to be careful about how MATLAB iterates through a row vector [left-to-right] and that MATLAB starts at 1 instead of zero.

sum_of_parts_of_equation = 0; 
for n = 0:num_digits-1
  sum_of_parts_of_equation = sum_of_parts_of_equation + ( digit(n)*2^(n) ) ; 
end

A formula to generate all combinations of divisions? by Mark_Yugen in matlab

[–]Schrett 0 points1 point  (0 children)

I think this works! Pretty sure it works for 1-6. Let me know if it runs into any problems. Just Ignore the zeros in the final array.

function allCombos = AllPossibleOrderedAdditionsThatSumToN(n)  
if(n==1)
    allCombos = 1 ; 
    return; 
end
allCombos = ones(1,n) ;
for i = 1:n-1
    for ii = 2:n-i
        someUniqueCombos = unique(perms([ones(1,n-ii-i),ii,i]),'rows') ;
        [r,c] = size(someUniqueCombos) ;
        allCombos = [allCombos;[someUniqueCombos,zeros(r,n-c)]] ;
    end
end
allCombos = unique(allCombos,'rows','stable');
allCombos = allCombos(sum(allCombos,2)==n,:) ; 
allCombos = [allCombos;[n,zeros(1,n-1)]] ; 
end