How do I save a SINGLE value from the workspace?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I am using the diff function to find the value of 0 of my function in the first derivative. Turns out I got the results shown in the image.
Now I need to know how I can save ONLY the value that is marked in a box of the image. Since later I need to perform a for and save the marked value for each iteration. Thank you.
2 commentaires
Luca Ferro
le 21 Fév 2023
could you share the data? if not, could you say what data type (array 24x2, struct,...) is the source?
Réponses (2)
Fangjun Jiang
le 21 Fév 2023
You will have to assign that value to a temparary variable and then save it.
a=rand(10,2);
%save test.mat a(8,:) % this will cause error
temp=a(8,:);
save test.mat temp;
0 commentaires
Star Strider
le 21 Fév 2023
‘Hi, is a data type 2x99. I need save the value x(:,1) when x(:,2) is near to 0. How I save this date.’
It depends what ‘near to 0’ means. One option is to look for the indices of the zero crossings —
x = [0:98; sin(2*pi*(0:98)/25)+randn(1,99)*0.05].' % Create Data
Near0Idx = find(diff(sign(x(:,2)))) % Indices Of Zero Crossings
figure
plot(x(:,1), x(:,2), 'DisplayName','Data')
hold on
plot(x(Near0Idx,1), x(Near0Idx,2), 'rs', 'DisplayName','Near to 0')
hold off
grid
axis('padded')
legend('Location','best')
If there are no zero-crossings, then equivalently something like this would work:
Offset = 1;
Near0Idx = find(diff(sign(x(:,2)-Offset)))
The ‘Offset’ value can be whatever works in your application, either positive or negative, and it could be either added or subtracted from ‘x(:,2)’.
.
.
0 commentaires
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!