How do I save a SINGLE value from the workspace?
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
Luca Ferro
2023-2-21
could you share the data? if not, could you say what data type (array 24x2, struct,...) is the source?
回答(2 个)
Fangjun Jiang
2023-2-21
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 个评论
Star Strider
2023-2-21
‘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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!