Scaling part of .k file in matlab
4 views (last 30 days)
Show older comments
Hi Guys,
I want to scale wheels of wheelchair (its mesh file-.k file). I want to scale wheels from the bottom of it. I am not able to do it. Can you please help? Here is my code
clear;
filename = 'manual_wc.k';
fileContent = fileread(filename);
lines = splitlines(fileContent);
partsToScale = [280017, 280007, 280005, 280015];
scale_factor = 1.367;
origin = [-83.04, -287.47, 305.03];
scaledLines = lines; % Copy content to modify
inNodeSection = false; % Flag for *NODE section
currentPartID = -1; % Variable to track the part ID
for i = 1:length(lines)
line = strtrim(lines{i});
if contains(line, '*PART')
inNodeSection = false; % Reset node flag
currentPartID = -1; % Reset part ID
nextLineData = sscanf(lines{i + 1}, '%f'); % Extract part ID
if ~isempty(nextLineData)
currentPartID = nextLineData(1); % Store part ID
end
elseif contains(line, '*NODE')
inNodeSection = true;
elseif contains(line, '*ELEMENT')
inNodeSection = false;
elseif inNodeSection && ~isempty(line) && isstrprop(line(1), 'digit')
if ismember(currentPartID, partsToScale)
relativeCoords = nodeData(2:4) - origin;
scaledCoords = relativeCoords * scale_factor;
newCoords = scaledCoords + origin;
scaledLines{i} = sprintf('%10d%16.6f%16.6f%16.6f', ...
nodeData(1), newCoords(1), newCoords(2), newCoords(3));
end
end
end
% Step 6: Write the modified .k file
output_filename = 'scaled_wheelchair.k'; % Output file name
fid = fopen(output_filename, 'w'); % Open file for writing
fprintf(fid, '%s\n', scaledLines{:}); % Write modified content line by line
fclose(fid); % Close the file
disp(['Scaled .k file saved as ', output_filename]);
Its my first time doing coding in matlab. Thanks a lot!
1 Comment
Stephen23
on 14 Feb 2025
Edited: Stephen23
on 14 Feb 2025
"I am not able to do it. Can you please help"
You wrote some code but did not tell us what the problem is. What is your code doing (or not doing) that you expect it to?
Are you getting an error? Or warnings? Or an unexpected output?
Tip for asking for help on forums: you do not need to ask "can you please help", everyone comes here to ask for help. But what we do not know are things like 1) what you expect that code to do 2) what the code actually does 3) what errors/warnings/messages it displays, etc. If you want help then you need to tell us sufficient information so that we can actually help you.
It would also help if you uploaded a sample data file by clicking the paperclip button.
Answers (0)
See Also
Categories
Find more on Historical Contests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!